thread_split: enable spawn highlight

This commit is contained in:
evanpelle
2025-02-01 12:05:11 -08:00
committed by Evan
parent 7d04d25e6f
commit 10a1f1af8e
7 changed files with 33 additions and 60 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ export class GameRunner {
this.currTurn++
this.game.executeNextTick()
if (this.game.ticks() % 10 == 0) {
if (this.game.inSpawnPhase() || this.game.ticks() % 10 == 0) {
this.game.players()
.forEach(p => this.playerToName.set(p.id(), placeName(this.game, p)))
}
+1 -1
View File
@@ -19,7 +19,7 @@ export class DevConfig extends DefaultConfig {
}
numSpawnPhaseTurns(): number {
return this.gameConfig().gameType == GameType.Singleplayer ? 40 : 200
return this.gameConfig().gameType == GameType.Singleplayer ? 400 : 200
// return 100
}
+6 -5
View File
@@ -1,7 +1,7 @@
import { Cell, Execution, MutableGame, MutablePlayer, PlayerInfo, PlayerType } from "../game/Game"
import { BotExecution } from "./BotExecution"
import { PlayerExecution } from "./PlayerExecution"
import { getSpawnCells } from "./Util"
import { getSpawnTiles } from "./Util"
export class SpawnExecution implements Execution {
@@ -25,17 +25,18 @@ export class SpawnExecution implements Execution {
}
const existing = this.mg.players().find(p => p.id() == this.playerInfo.id)
const tile = this.mg.tile(this.cell)
if (existing) {
existing.tiles().forEach(t => existing.relinquish(t))
getSpawnCells(this.mg, this.cell).forEach(c => {
existing.conquer(this.mg.tile(c))
getSpawnTiles(tile).forEach(t => {
existing.conquer(t)
})
return
}
const player = this.mg.addPlayer(this.playerInfo, this.mg.config().startManpower(this.playerInfo))
getSpawnCells(this.mg, this.cell).forEach(c => {
player.conquer(this.mg.tile(c))
getSpawnTiles(tile).forEach(t => {
player.conquer(t)
})
this.mg.addExecution(new PlayerExecution(player.id()))
if (player.type() == PlayerType.Bot) {
+4 -21
View File
@@ -1,27 +1,10 @@
import { Game, Cell, Tile } from "../game/Game";
import { and, bfs, euclDist } from "../Util";
export function getSpawnCells(gs: Game, cell: Cell): Cell[] {
let result: Cell[] = [];
for (let dx = -2; dx <= 2; dx++) {
for (let dy = -2; dy <= 2; dy++) {
let c = new Cell(cell.x + dx, cell.y + dy);
if (!gs.isOnMap(c)) {
continue;
}
if (Math.abs(dx) === 2 && Math.abs(dy) === 2) {
continue;
}
if (gs.tile(c).terrain().isWater()) {
continue;
}
if (gs.tile(c).hasOwner()) {
continue;
}
result.push(c);
}
}
return result;
export function getSpawnTiles(tile: Tile): Tile[] {
return Array.from(bfs(tile, euclDist(tile, 4)))
.filter(t => !t.hasOwner() && t.terrain().isLand())
}
export function closestTwoTiles(x: Iterable<Tile>, y: Iterable<Tile>): { x: Tile, y: Tile } {
+3
View File
@@ -332,6 +332,9 @@ export class GameImpl implements MutableGame {
}
conquer(owner: PlayerImpl, tile: Tile): void {
if (!tile.terrain().isLand()) {
throw Error(`cannot conquer water`)
}
const tileImpl = tile as TileImpl
let previousOwner = tileImpl._owner
if (previousOwner.isPlayer()) {