improved terrain api

This commit is contained in:
evanpelle
2024-08-21 19:51:01 -07:00
parent 3b9ccf49b1
commit 5e7c206f0d
16 changed files with 61 additions and 52 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
import PriorityQueue from "priority-queue-typescript";
import {Cell, Execution, MutableGame, MutablePlayer, PlayerID, Player, TerrainTypes, TerraNullius, Tile} from "../Game";
import {Cell, Execution, MutableGame, MutablePlayer, PlayerID, TerraNullius, Tile} from "../Game";
import {PseudoRandom} from "../PseudoRandom";
import {manhattanDist} from "../Util";
import {Config, PlayerConfig} from "../configuration/Config";
@@ -145,13 +145,13 @@ export class AttackExecution implements Execution {
}
for (const tile of existingBorder) {
for (const neighbor of tile.neighbors()) {
if (neighbor.terrain() == TerrainTypes.Water || neighbor.owner() != this.target) {
if (neighbor.isWater() || neighbor.owner() != this.target) {
continue
}
newBorder.add(neighbor)
this.numTilesWithEnemy += 1
let numOwnedByMe = neighbor.neighbors()
.filter(t => t.terrain() == TerrainTypes.Land)
.filter(t => t.isLand())
.filter(t => t.owner() == this._owner)
.length
let dist = 0
+2 -2
View File
@@ -1,5 +1,5 @@
import PriorityQueue from "priority-queue-typescript";
import {Boat, Cell, Execution, MutableBoat, MutableGame, MutablePlayer, Player, PlayerID, TerrainTypes, Tile} from "../Game";
import {Boat, Cell, Execution, MutableBoat, MutableGame, MutablePlayer, Player, PlayerID, Tile} from "../Game";
import {manhattanDist} from "../Util";
import {AttackExecution} from "./AttackExecution";
import {Config, PlayerConfig} from "../configuration/Config";
@@ -165,7 +165,7 @@ export class AStar {
}
for (const neighbor of this.current.neighbors()) {
if (neighbor != this.dst && neighbor.terrain() != TerrainTypes.Water) continue; // Skip non-water tiles
if (neighbor != this.dst && neighbor.isLand()) continue; // Skip non-water tiles
const tentativeGScore = this.gScore.get(this.current)! + 1; // Assuming uniform cost
+2 -2
View File
@@ -1,5 +1,5 @@
import {Config, PlayerConfig} from "../configuration/Config";
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerrainTypes, TerraNullius} from "../Game"
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerraNullius} from "../Game"
import {PseudoRandom} from "../PseudoRandom"
import {AttackExecution} from "./AttackExecution";
@@ -38,7 +38,7 @@ export class BotExecution implements Execution {
if (this.neighborsTerra) {
for (const b of this.bot.borderTiles()) {
for (const n of b.neighbors()) {
if (n.owner() == this.gs.terraNullius() && n.terrain() == TerrainTypes.Land) {
if (n.owner() == this.gs.terraNullius() && n.isLand()) {
this.sendAttack(this.gs.terraNullius())
return
}
+2 -2
View File
@@ -1,4 +1,4 @@
import {Cell, Game, TerrainTypes} from "../Game";
import {Cell, Game} from "../Game";
import {PseudoRandom} from "../PseudoRandom";
import {SpawnIntent} from "../Schemas";
import {getSpawnCells} from "./Util";
@@ -19,7 +19,7 @@ export class BotSpawner {
this.numFreeTiles = 0;
this.gs.forEachTile(tile => {
if (tile.terrain() == TerrainTypes.Water) {
if (tile.isWater()) {
return;
}
if (tile.hasOwner()) {
+2 -2
View File
@@ -1,4 +1,4 @@
import {Game, Cell, TerrainTypes} from "../Game";
import {Game, Cell} from "../Game";
export function getSpawnCells(gs: Game, cell: Cell): Cell[] {
@@ -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).terrain() != TerrainTypes.Land) {
if (gs.tile(c).isWater()) {
continue;
}
if (gs.tile(c).hasOwner()) {