have core/ directory use consolex for remote logging

This commit is contained in:
evanpelle
2024-12-18 12:00:00 -08:00
parent 642d5dc4ca
commit ff02d9d8b6
31 changed files with 91 additions and 66 deletions
+2 -2
View File
@@ -130,8 +130,8 @@ export class AttackExecution implements Execution {
}
let numTilesPerTick = this.mg.config().attackTilesPerTick(this._owner, this.target, this.border.size + this.random.nextInt(0, 5))
// console.log(`num tiles per tick: ${numTilesPerTick}`)
// console.log(`num execs: ${this.mg.executions().length}`)
// consolex.log(`num tiles per tick: ${numTilesPerTick}`)
// consolex.log(`num execs: ${this.mg.executions().length}`)
while (numTilesPerTick > 0) {
+2 -1
View File
@@ -5,6 +5,7 @@ import { SerialAStar } from "../pathfinding/SerialAStar";
import { PseudoRandom } from "../PseudoRandom";
import { distSort, distSortUnit, manhattanDist } from "../Util";
import { ShellExecution } from "./ShellExecution";
import { consolex } from "../Consolex";
export class BattleshipExecution implements Execution {
private random: PseudoRandom
@@ -66,7 +67,7 @@ export class BattleshipExecution implements Execution {
case PathFindResultType.Pending:
return
case PathFindResultType.PathNotFound:
console.log(`path not found to patrol tile`)
consolex.log(`path not found to patrol tile`)
this.patrolTile = this.randomTile()
break
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import {Cell, Game, PlayerType, Tile, TileEvent} from "../game/Game";
import {PseudoRandom} from "../PseudoRandom";
import {GameID, SpawnIntent} from "../Schemas";
@@ -16,7 +17,7 @@ export class BotSpawner {
let tries = 0
while (this.bots.length < numBots) {
if (tries > 10000) {
console.log('too many retries while spawning bots, giving up')
consolex.log('too many retries while spawning bots, giving up')
return this.bots
}
const spawn = this.spawnBot("Bot" + this.bots.length)
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import { Cell, DefenseBonus, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
import { bfs, dist } from "../Util";
@@ -21,7 +22,7 @@ export class CityExecution implements Execution {
if (this.city == null) {
const spawnTile = this.player.canBuild(UnitType.City, this.tile)
if (spawnTile == false) {
console.warn('cannot build Defense Post')
consolex.warn('cannot build Defense Post')
this.active = false
return
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import { Cell, DefenseBonus, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
import { bfs, dist } from "../Util";
@@ -23,7 +24,7 @@ export class DefensePostExecution implements Execution {
if (this.post == null) {
const spawnTile = this.player.canBuild(UnitType.DefensePost, this.tile)
if (spawnTile == false) {
console.warn('cannot build Defense Post')
consolex.warn('cannot build Defense Post')
this.active = false
return
}
+3 -2
View File
@@ -4,6 +4,7 @@ import { PathFindResultType } from "../pathfinding/AStar";
import { SerialAStar } from "../pathfinding/SerialAStar";
import { PseudoRandom } from "../PseudoRandom";
import { distSort, distSortUnit, manhattanDist } from "../Util";
import { consolex } from "../Consolex";
export class DestroyerExecution implements Execution {
private random: PseudoRandom
@@ -72,7 +73,7 @@ export class DestroyerExecution implements Execution {
case PathFindResultType.Pending:
return
case PathFindResultType.PathNotFound:
console.log(`path not found to patrol tile`)
consolex.log(`path not found to patrol tile`)
this.patrolTile = this.randomTile()
break
}
@@ -110,7 +111,7 @@ export class DestroyerExecution implements Execution {
case PathFindResultType.Pending:
break
case PathFindResultType.PathNotFound:
console.log(`path not found to target`)
consolex.log(`path not found to target`)
break
}
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import {AllPlayers, Execution, MutableGame, MutablePlayer, PlayerID} from "../game/Game";
export class DonateExecution implements Execution {
@@ -26,7 +27,7 @@ export class DonateExecution implements Execution {
if (this.sender.canDonate(this.recipient)) {
this.sender.donate(this.recipient, this.troops)
} else {
console.warn(`cannot send tropps from ${this.sender} to ${this.recipient}`)
consolex.warn(`cannot send tropps from ${this.sender} to ${this.recipient}`)
}
this.active = false
}
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import {AllPlayers, Execution, MutableGame, MutablePlayer, PlayerID} from "../game/Game";
export class EmojiExecution implements Execution {
@@ -23,7 +24,7 @@ export class EmojiExecution implements Execution {
if (this.requestor.canSendEmoji(this.recipient)) {
this.requestor.sendEmoji(this.recipient, this.emoji)
} else {
console.warn(`cannot send emoji from ${this.requestor} to ${this.recipient}`)
consolex.warn(`cannot send emoji from ${this.requestor} to ${this.recipient}`)
}
this.active = false
}
+3 -2
View File
@@ -10,6 +10,7 @@ import { PathFinder } from "../pathfinding/PathFinding";
import { DestroyerExecution } from "./DestroyerExecution";
import { BattleshipExecution } from "./BattleshipExecution";
import { GameID } from "../Schemas";
import { consolex } from "../Consolex";
export class FakeHumanExecution implements Execution {
@@ -42,7 +43,7 @@ export class FakeHumanExecution implements Execution {
if (ticks % this.random.nextInt(5, 30) == 0) {
const rl = this.randomLand()
if (rl == null) {
console.warn(`cannot spawn ${this.playerInfo.name}`)
consolex.warn(`cannot spawn ${this.playerInfo.name}`)
return
}
this.mg.addExecution(new SpawnExecution(
@@ -180,7 +181,7 @@ export class FakeHumanExecution implements Execution {
}
const canBuild = this.player.canBuild(UnitType.Destroyer, targetTile)
if (canBuild == false) {
console.warn('cannot spawn destroyer')
consolex.warn('cannot spawn destroyer')
return false
}
switch (shipType) {
+2 -1
View File
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, Player, PlayerID, Tile, Unit, UnitType } from "../game/Game";
export class MissileSiloExecution implements Execution {
@@ -22,7 +23,7 @@ export class MissileSiloExecution implements Execution {
if (this.silo == null) {
const tile = this.mg.tile(this.cell)
if (!this.player.canBuild(UnitType.MissileSilo, tile)) {
console.warn(`player ${this.player} cannot build port at ${this.cell}`)
consolex.warn(`player ${this.player} cannot build port at ${this.cell}`)
this.active = false
return
}
+3 -2
View File
@@ -4,6 +4,7 @@ import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { PseudoRandom } from "../PseudoRandom";
import { bfs, dist, distSortUnit, euclideanDist, manhattanDist } from "../Util";
import { consolex } from "../Consolex";
export class NukeExecution implements Execution {
@@ -35,7 +36,7 @@ export class NukeExecution implements Execution {
if (this.nuke == null) {
const spawn = this.player.canBuild(this.type, this.dst)
if (spawn == false) {
console.warn(`cannot build Nuke`)
consolex.warn(`cannot build Nuke`)
this.active = false
return
}
@@ -55,7 +56,7 @@ export class NukeExecution implements Execution {
case PathFindResultType.Pending:
break
case PathFindResultType.PathNotFound:
console.warn(`nuke cannot find path from ${this.nuke.tile()} to ${this.dst}`)
consolex.warn(`nuke cannot find path from ${this.nuke.tile()} to ${this.dst}`)
this.active = false
return
}
+4 -3
View File
@@ -2,6 +2,7 @@ import { Config } from "../configuration/Config"
import { Execution, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile } from "../game/Game"
import { bfs, calculateBoundingBox, getMode, inscribed, simpleHash } from "../Util"
import { GameImpl } from "../game/GameImpl"
import { consolex } from "../Consolex"
export class PlayerExecution implements Execution {
@@ -71,7 +72,7 @@ export class PlayerExecution implements Execution {
this.removeClusters()
const end = performance.now()
if (end - start > 1000) {
console.log(`player ${this.player.name()}, took ${end - start}ms`)
consolex.log(`player ${this.player.name()}, took ${end - start}ms`)
}
}
}
@@ -138,7 +139,7 @@ export class PlayerExecution implements Execution {
const arr = Array.from(cluster)
const mode = getMode(arr.flatMap(t => t.neighbors()).filter(t => t.hasOwner() && t.owner() != this.player).map(t => t.owner().id()))
if (!this.mg.hasPlayer(mode)) {
console.warn('mode is not found')
consolex.warn('mode is not found')
return
}
const firstTile = arr[0]
@@ -147,7 +148,7 @@ export class PlayerExecution implements Execution {
const modePlayer = this.mg.player(mode)
if (modePlayer == null) {
console.warn('mode player is null')
consolex.warn('mode player is null')
}
for (const tile of tiles) {
modePlayer.conquer(tile)
+5 -4
View File
@@ -6,6 +6,7 @@ import { PseudoRandom } from "../PseudoRandom";
import { bfs, dist, manhattanDist } from "../Util";
import { TradeShipExecution } from "./TradeShipExecution";
import { ParallelAStar, WorkerClient } from "../worker/WorkerClient";
import { consolex } from "../Consolex";
export class PortExecution implements Execution {
@@ -35,7 +36,7 @@ export class PortExecution implements Execution {
const tile = this.mg.tile(this.cell)
const player = this.mg.player(this._owner)
if (!player.canBuild(UnitType.Port, tile)) {
console.warn(`player ${player} cannot build port at ${this.cell}`)
consolex.warn(`player ${player} cannot build port at ${this.cell}`)
this.active = false
return
}
@@ -44,7 +45,7 @@ export class PortExecution implements Execution {
.sort((a, b) => manhattanDist(a.cell(), tile.cell()) - manhattanDist(b.cell(), tile.cell()))
if (spawns.length == 0) {
console.warn(`cannot find spawn for port`)
consolex.warn(`cannot find spawn for port`)
this.active = false
return
}
@@ -78,13 +79,13 @@ export class PortExecution implements Execution {
case PathFindResultType.Pending:
break
case PathFindResultType.PathNotFound:
console.warn(`path not found to port`)
consolex.warn(`path not found to port`)
break
}
continue
}
const asyncPF = this.worker.createParallelAStar(this.port.tile(), port.tile(), 25, [TerrainType.Ocean])
// console.log(`adding new port path from ${this.player().name()}:${this.port.tile().cell()} to ${port.owner().name()}:${port.tile().cell()}`)
// consolex.log(`adding new port path from ${this.player().name()}:${this.port.tile().cell()} to ${port.owner().name()}:${port.tile().cell()}`)
this.computingPaths.set(port, asyncPF)
}
@@ -1,3 +1,4 @@
import { consolex } from "../Consolex";
import { Execution, MutableGame, MutablePlayer, PlayerID } from "../game/Game";
export class SetTargetTroopRatioExecution implements Execution {
@@ -15,7 +16,7 @@ export class SetTargetTroopRatioExecution implements Execution {
tick(ticks: number): void {
if (this.targetTroopsRatio < 0 || this.targetTroopsRatio > 1) {
console.warn(`target troop ratio of ${this.targetTroopsRatio} for player ${this.player} invalid`)
consolex.warn(`target troop ratio of ${this.targetTroopsRatio} for player ${this.player} invalid`)
} else {
this.player.setTargetTroopRatio(this.targetTroopsRatio)
}
+2 -1
View File
@@ -1,6 +1,7 @@
import { Execution, MutableGame, MutablePlayer, MutableUnit, Tile, Unit, UnitType } from "../game/Game";
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { consolex } from "../Consolex";
export class ShellExecution implements Execution {
@@ -43,7 +44,7 @@ export class ShellExecution implements Execution {
case PathFindResultType.Pending:
return
case PathFindResultType.PathNotFound:
console.log(`Shell ${this.shell} could not find target`)
consolex.log(`Shell ${this.shell} could not find target`)
this.active = false
this.shell.delete(false)
return
+3 -2
View File
@@ -6,6 +6,7 @@ import { PathFindResultType } from "../pathfinding/AStar";
import { SerialAStar } from "../pathfinding/SerialAStar";
import { PseudoRandom } from "../PseudoRandom";
import { bfs, dist, distSortUnit, manhattanDist } from "../Util";
import { consolex } from "../Consolex";
export class TradeShipExecution implements Execution {
@@ -35,7 +36,7 @@ export class TradeShipExecution implements Execution {
if (this.tradeShip == null) {
const spawn = this.origOwner.canBuild(UnitType.TradeShip, this.srcPort.tile())
if (spawn == false) {
console.warn(`cannot build trade ship`)
consolex.warn(`cannot build trade ship`)
this.active = false
return
}
@@ -86,7 +87,7 @@ export class TradeShipExecution implements Execution {
this.tradeShip.move(result.tile)
break
case PathFindResultType.PathNotFound:
console.warn('captured trade ship cannot find route')
consolex.warn('captured trade ship cannot find route')
this.active = false
break
}
+4 -3
View File
@@ -5,6 +5,7 @@ import { DisplayMessageEvent, MessageType } from "../../client/graphics/layers/E
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { SerialAStar } from "../pathfinding/SerialAStar";
import { consolex } from "../Consolex";
export class TransportShipExecution implements Execution {
@@ -68,13 +69,13 @@ export class TransportShipExecution implements Execution {
this.dst = targetTransportTile(this.mg, this.mg.tile(this.cell))
if (this.dst == null) {
console.warn(`${this.attacker} cannot send ship to ${this.target}, cannot find attack tile`)
consolex.warn(`${this.attacker} cannot send ship to ${this.target}, cannot find attack tile`)
this.active = false
return
}
const src = this.attacker.canBuild(UnitType.TransportShip, this.dst)
if (src == false) {
console.warn(`can't build transport ship`)
consolex.warn(`can't build transport ship`)
this.active = false
return
}
@@ -124,7 +125,7 @@ export class TransportShipExecution implements Execution {
break
case PathFindResultType.PathNotFound:
// TODO: add to poisoned port list
console.warn(`path not found tot dst`)
consolex.warn(`path not found tot dst`)
this.boat.delete(false)
this.active = false
return
@@ -1,3 +1,4 @@
import { consolex } from "../../Consolex";
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
export class AllianceRequestExecution implements Execution {
@@ -16,9 +17,9 @@ export class AllianceRequestExecution implements Execution {
tick(ticks: number): void {
if (this.requestor.isAlliedWith(this.recipient)) {
console.warn('already allied')
consolex.warn('already allied')
} else if (this.requestor.recentOrPendingAllianceRequestWith(this.recipient)) {
console.warn('recent or pending alliance request')
consolex.warn('recent or pending alliance request')
} else {
this.requestor.createAllianceRequest(this.recipient)
}
@@ -1,3 +1,4 @@
import { consolex } from "../../Consolex";
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
export class AllianceRequestReplyExecution implements Execution {
@@ -16,11 +17,11 @@ export class AllianceRequestReplyExecution implements Execution {
tick(ticks: number): void {
if (this.requestor.isAlliedWith(this.recipient)) {
console.warn('already allied')
consolex.warn('already allied')
} else {
const request = this.requestor.outgoingAllianceRequests().find(ar => ar.recipient() == this.recipient)
if (request == null) {
console.warn('no alliance request found')
consolex.warn('no alliance request found')
} else {
if (this.accept) {
request.accept()
@@ -1,3 +1,4 @@
import { consolex } from "../../Consolex";
import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game";
export class BreakAllianceExecution implements Execution {
@@ -15,7 +16,7 @@ export class BreakAllianceExecution implements Execution {
tick(ticks: number): void {
const alliance = this.requestor.allianceWith(this.recipient)
if (alliance == null) {
console.warn('cant break alliance, not allied')
consolex.warn('cant break alliance, not allied')
} else {
this.requestor.breakAlliance(alliance)
}