put methods onto terraintile

This commit is contained in:
Evan
2025-01-02 15:35:13 -08:00
parent 8443095d89
commit dab427d614
30 changed files with 439 additions and 149 deletions
+3 -3
View File
@@ -173,12 +173,12 @@ export class AttackExecution implements Execution {
private addNeighbors(tile: Tile) {
for (const neighbor of tile.neighbors()) {
if (neighbor.isWater() || neighbor.owner() != this.target) {
if (neighbor.terrain().isWater() || neighbor.owner() != this.target) {
continue
}
this.border.add(neighbor)
let numOwnedByMe = neighbor.neighbors()
.filter(t => t.isLand())
.filter(t => t.terrain().isLand())
.filter(t => t.owner() == this._owner)
.length
let dist = 0
@@ -189,7 +189,7 @@ export class AttackExecution implements Execution {
numOwnedByMe = 10
}
let mag = 0
switch (tile.terrain()) {
switch (tile.terrain().type()) {
case TerrainType.Plains:
mag = 1
break
+2 -2
View File
@@ -34,7 +34,7 @@ export class BattleshipExecution implements Execution {
init(mg: MutableGame, ticks: number): void {
this.pathfinder = PathFinder.Mini(mg, 5000, t => t.terrainType() == TerrainType.Ocean)
this.pathfinder = PathFinder.Mini(mg, 5000, t => t.type() == TerrainType.Ocean)
this._owner = mg.player(this.playerID)
this.mg = mg
this.patrolCenterTile = mg.tile(this.cell)
@@ -133,7 +133,7 @@ export class BattleshipExecution implements Execution {
continue
}
const tile = this.mg.tile(cell)
if (!tile.isOcean()) {
if (!tile.terrain().isOcean()) {
continue
}
return tile
+1 -1
View File
@@ -56,7 +56,7 @@ export class BotExecution implements Execution {
if (this.neighborsTerraNullius) {
for (const b of this.bot.borderTiles()) {
for (const n of b.neighbors()) {
if (n.owner() == this.mg.terraNullius() && n.isLand()) {
if (n.owner() == this.mg.terraNullius() && n.terrain().isLand()) {
this.sendAttack(this.mg.terraNullius())
return
}
+1 -1
View File
@@ -34,7 +34,7 @@ export class BotSpawner {
spawnBot(botName: string): SpawnIntent | null {
const tile = this.randTile()
if (!tile.isLand()) {
if (!tile.terrain().isLand()) {
return null
}
for (const spawn of this.bots) {
+1 -1
View File
@@ -30,7 +30,7 @@ export class DefensePostExecution implements Execution {
}
this.post = this.player.buildUnit(UnitType.DefensePost, 0, spawnTile)
bfs(spawnTile, dist(spawnTile, this.mg.config().defensePostRange())).forEach(t => {
if (t.isLand()) {
if (t.terrain().isLand()) {
this.defenseBonuses.push(this.mg.addTileDefenseBonus(t, this.post, this.mg.config().defensePostDefenseBonus()))
}
})
+2 -2
View File
@@ -30,7 +30,7 @@ export class DestroyerExecution implements Execution {
init(mg: MutableGame, ticks: number): void {
this.pathfinder = PathFinder.Mini(mg, 5000, t => t.terrainType() == TerrainType.Ocean)
this.pathfinder = PathFinder.Mini(mg, 5000, t => t.type() == TerrainType.Ocean)
this._owner = mg.player(this.playerID)
this.mg = mg
this.patrolCenterTile = mg.tile(this.cell)
@@ -141,7 +141,7 @@ export class DestroyerExecution implements Execution {
continue
}
const tile = this.mg.tile(cell)
if (!tile.isOcean()) {
if (!tile.terrain().isOcean()) {
continue
}
return tile
+11 -11
View File
@@ -91,7 +91,7 @@ export class FakeHumanExecution implements Execution {
this.handleEnemies()
this.handleUnits()
const enemyborder = Array.from(this.player.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.isLand() && t.owner() != this.player)
const enemyborder = Array.from(this.player.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.terrain().isLand() && t.owner() != this.player)
if (enemyborder.length == 0) {
if (this.random.chance(5)) {
@@ -243,8 +243,8 @@ export class FakeHumanExecution implements Execution {
private maybeSendBoatAttack(other: Player) {
const closest = closestTwoTiles(
Array.from(this.player.borderTiles()).filter(t => t.isOceanShore()),
Array.from(other.borderTiles()).filter(t => t.isOceanShore())
Array.from(this.player.borderTiles()).filter(t => t.terrain().isOceanShore()),
Array.from(other.borderTiles()).filter(t => t.terrain().isOceanShore())
)
if (closest == null) {
return
@@ -262,7 +262,7 @@ export class FakeHumanExecution implements Execution {
private handleUnits() {
const ports = this.player.units(UnitType.Port)
if (ports.length == 0 && this.player.gold() > this.cost(UnitType.Port)) {
const oceanTiles = Array.from(this.player.borderTiles()).filter(t => t.isOceanShore())
const oceanTiles = Array.from(this.player.borderTiles()).filter(t => t.terrain().isOceanShore())
if (oceanTiles.length > 0) {
const buildTile = this.random.randElement(oceanTiles)
this.mg.addExecution(new PortExecution(this.player.id(), buildTile.cell()))
@@ -359,7 +359,7 @@ export class FakeHumanExecution implements Execution {
continue
}
const tile = this.mg.tile(cell)
if (!tile.isOcean()) {
if (!tile.terrain().isOcean()) {
continue
}
return tile
@@ -402,7 +402,7 @@ export class FakeHumanExecution implements Execution {
}
if (oceanShore == null) {
oceanShore = Array.from(this.player.borderTiles()).filter(t => t.isOceanShore())
oceanShore = Array.from(this.player.borderTiles()).filter(t => t.terrain().isOceanShore())
}
if (oceanShore.length == 0) {
return
@@ -412,9 +412,9 @@ export class FakeHumanExecution implements Execution {
const otherShore = Array.from(
bfs(
src,
and((t) => t.isOcean() || t.isOceanShore(), dist(src, 200))
and((t) => t.terrain().isOcean() || t.terrain().isOceanShore(), dist(src, 200))
)
).filter(t => t.isOceanShore() && t.owner() != this.player)
).filter(t => t.terrain().isOceanShore() && t.owner() != this.player)
if (otherShore.length == 0) {
return
@@ -453,8 +453,8 @@ export class FakeHumanExecution implements Execution {
continue
}
const tile = this.mg.tile(cell)
if (tile.isLand() && !tile.hasOwner()) {
if (tile.terrain() == TerrainType.Mountain && this.random.chance(2)) {
if (tile.terrain().isLand() && !tile.hasOwner()) {
if (tile.terrain().type() == TerrainType.Mountain && this.random.chance(2)) {
continue
}
return tile
@@ -474,7 +474,7 @@ export class FakeHumanExecution implements Execution {
}
isSmallIsland(tile: Tile): boolean {
return bfs(tile, and((t) => t.isLand(), dist(tile, 10))).size < 50
return bfs(tile, and((t) => t.terrain().isLand(), dist(tile, 10))).size < 50
}
owner(): MutablePlayer {
+1 -1
View File
@@ -92,7 +92,7 @@ export class NukeExecution implements Execution {
const prev = attacked.get(mp)
attacked.set(mp, prev + 1)
}
if (tile.isLand()) {
if (tile.terrain().isLand()) {
this.mg.addFallout(tile)
}
}
+2 -2
View File
@@ -112,7 +112,7 @@ export class PlayerExecution implements Execution {
private surroundedBySamePlayer(cluster: Set<Tile>): false | Player {
const enemies = new Set<Player>()
for (const tile of cluster) {
if (tile.isOceanShore() || tile.neighbors().find(n => !n.hasOwner())) {
if (tile.terrain().isOceanShore() || tile.neighbors().find(n => !n.hasOwner())) {
return false
}
tile.neighbors()
@@ -131,7 +131,7 @@ export class PlayerExecution implements Execution {
private isSurrounded(cluster: Set<Tile>): boolean {
let enemyTiles = new Set<Tile>()
for (const tile of cluster) {
if (tile.isOceanShore()) {
if (tile.terrain().isOceanShore()) {
return false
}
tile.neighbors()
+3 -3
View File
@@ -41,7 +41,7 @@ export class PortExecution implements Execution {
return
}
const spawns = Array.from(bfs(tile, dist(tile, 20)))
.filter(t => t.isOceanShore() && t.owner() == player)
.filter(t => t.terrain().isOceanShore() && t.owner() == player)
.sort((a, b) => manhattanDist(a.cell(), tile.cell()) - manhattanDist(b.cell(), tile.cell()))
if (spawns.length == 0) {
@@ -89,7 +89,7 @@ export class PortExecution implements Execution {
this.mg.terrainMap(),
this.mg.terrainMiniMap(),
this.port.tile(), port.tile(),
sn => sn.terrainType() == TerrainType.Ocean,
sn => sn.type() == TerrainType.Ocean,
10_000,
25
)
@@ -109,7 +109,7 @@ export class PortExecution implements Execution {
const port = this.random.randElement(portConnections)
const path = this.portPaths.get(port)
if (path != null) {
const pf = PathFinder.Mini(this.mg, 10, (sn) => sn.terrainType() == TerrainType.Ocean)
const pf = PathFinder.Mini(this.mg, 10, (sn) => sn.type() == TerrainType.Ocean)
this.mg.addExecution(new TradeShipExecution(this.player().id(), this.port, port, pf, path))
}
}
+1 -1
View File
@@ -44,7 +44,7 @@ export class TransportShipExecution implements Execution {
init(mg: MutableGame, ticks: number) {
this.lastMove = ticks
this.mg = mg
this.pathFinder = PathFinder.Mini(mg, 10_000, t => t.terrainType() == TerrainType.Ocean, 2)
this.pathFinder = PathFinder.Mini(mg, 10_000, t => t.type() == TerrainType.Ocean, 2)
this.attacker = mg.player(this.attackerID)
+1 -1
View File
@@ -12,7 +12,7 @@ export function getSpawnCells(gs: Game, cell: Cell): Cell[] {
if (Math.abs(dx) === 2 && Math.abs(dy) === 2) {
continue;
}
if (gs.tile(c).isWater()) {
if (gs.tile(c).terrain().isWater()) {
continue;
}
if (gs.tile(c).hasOwner()) {