add nuke button

This commit is contained in:
evanpelle
2024-10-19 10:04:40 -07:00
parent 42f0415c55
commit a81dbda071
6 changed files with 44 additions and 7 deletions
+9 -3
View File
@@ -1,5 +1,6 @@
import {Cell, Execution, MutableGame, MutablePlayer, PlayerID, Tile} from "../game/Game";
import {bfs, dist} from "../Util";
import {PseudoRandom} from "../PseudoRandom";
import {bfs, dist, euclideanDist, manhattanDist} from "../Util";
export class NukeExecution implements Execution {
@@ -22,12 +23,17 @@ export class NukeExecution implements Execution {
this.mg = mg
this.sender = mg.player(this.senderID)
if (this.magnitude == null) {
this.magnitude = 50
this.magnitude = 70
}
const rand = new PseudoRandom(mg.ticks())
const tile = mg.tile(this.cell)
this.toDestroy = bfs(tile, dist(tile, this.magnitude))
this.toDestroy = bfs(tile, (n: Tile) => {
const d = euclideanDist(tile.cell(), n.cell())
return (d <= this.magnitude || rand.chance(2)) && d <= this.magnitude + 30
})
}
tick(ticks: number): void {
for (const tile of this.toDestroy) {
const owner = tile.owner()