This commit is contained in:
Scott Anderson
2025-08-24 21:32:32 -04:00
parent eaefecb00f
commit 809d60ff58
95 changed files with 1385 additions and 1424 deletions
@@ -86,9 +86,9 @@ describe("SAM", () => {
const nuke = attacker.buildUnit(UnitType.AtomBomb, game.ref(1, 1), {
targetTile: game.ref(3, 1),
trajectory: [
{ tile: game.ref(1, 1), targetable: true },
{ tile: game.ref(2, 1), targetable: true },
{ tile: game.ref(3, 1), targetable: true },
{ targetable: true, tile: game.ref(1, 1) },
{ targetable: true, tile: game.ref(2, 1) },
{ targetable: true, tile: game.ref(3, 1) },
],
});
executeTicks(game, 3);
@@ -102,17 +102,17 @@ describe("SAM", () => {
attacker.buildUnit(UnitType.AtomBomb, game.ref(2, 1), {
targetTile: game.ref(3, 1),
trajectory: [
{ tile: game.ref(1, 1), targetable: true },
{ tile: game.ref(2, 1), targetable: true },
{ tile: game.ref(3, 1), targetable: true },
{ targetable: true, tile: game.ref(1, 1) },
{ targetable: true, tile: game.ref(2, 1) },
{ targetable: true, tile: game.ref(3, 1) },
],
});
attacker.buildUnit(UnitType.AtomBomb, game.ref(1, 2), {
targetTile: game.ref(1, 3),
trajectory: [
{ tile: game.ref(1, 1), targetable: true },
{ tile: game.ref(1, 2), targetable: true },
{ tile: game.ref(1, 3), targetable: true },
{ targetable: true, tile: game.ref(1, 1) },
{ targetable: true, tile: game.ref(1, 2) },
{ targetable: true, tile: game.ref(1, 3) },
],
});
expect(attacker.units(UnitType.AtomBomb)).toHaveLength(2);
@@ -130,9 +130,9 @@ describe("SAM", () => {
const nuke = attacker.buildUnit(UnitType.AtomBomb, game.ref(1, 1), {
targetTile: game.ref(1, 3),
trajectory: [
{ tile: game.ref(1, 1), targetable: true },
{ tile: game.ref(2, 1), targetable: true },
{ tile: game.ref(3, 1), targetable: true },
{ targetable: true, tile: game.ref(1, 1) },
{ targetable: true, tile: game.ref(2, 1) },
{ targetable: true, tile: game.ref(3, 1) },
],
});
@@ -158,9 +158,9 @@ describe("SAM", () => {
const nuke = attacker.buildUnit(UnitType.AtomBomb, game.ref(1, 1), {
targetTile: game.ref(1, 3),
trajectory: [
{ tile: game.ref(1, 1), targetable: true },
{ tile: game.ref(1, 2), targetable: true },
{ tile: game.ref(1, 3), targetable: true },
{ targetable: true, tile: game.ref(1, 1) },
{ targetable: true, tile: game.ref(1, 2) },
{ targetable: true, tile: game.ref(1, 3) },
],
});
@@ -22,66 +22,66 @@ describe("TradeShipExecution", () => {
});
game.displayMessage = jest.fn();
origOwner = {
canBuild: jest.fn(() => true),
buildUnit: jest.fn((type, spawn, opts) => tradeShip),
displayName: jest.fn(() => "Origin"),
addGold: jest.fn(),
units: jest.fn(() => [dstPort]),
unitCount: jest.fn(() => 1),
id: jest.fn(() => 1),
buildUnit: jest.fn((type, spawn, opts) => tradeShip),
canBuild: jest.fn(() => true),
canTrade: jest.fn(() => true),
displayName: jest.fn(() => "Origin"),
id: jest.fn(() => 1),
unitCount: jest.fn(() => 1),
units: jest.fn(() => [dstPort]),
} as any;
dstOwner = {
id: jest.fn(() => 2),
addGold: jest.fn(),
displayName: jest.fn(() => "Destination"),
units: jest.fn(() => [dstPort]),
unitCount: jest.fn(() => 1),
canTrade: jest.fn(() => true),
displayName: jest.fn(() => "Destination"),
id: jest.fn(() => 2),
unitCount: jest.fn(() => 1),
units: jest.fn(() => [dstPort]),
} as any;
pirate = {
id: jest.fn(() => 3),
addGold: jest.fn(),
displayName: jest.fn(() => "Destination"),
units: jest.fn(() => [piratePort]),
unitCount: jest.fn(() => 1),
canTrade: jest.fn(() => true),
displayName: jest.fn(() => "Destination"),
id: jest.fn(() => 3),
unitCount: jest.fn(() => 1),
units: jest.fn(() => [piratePort]),
} as any;
piratePort = {
tile: jest.fn(() => 40011),
owner: jest.fn(() => pirate),
isActive: jest.fn(() => true),
owner: jest.fn(() => pirate),
tile: jest.fn(() => 40011),
} as any;
srcPort = {
tile: jest.fn(() => 20011),
owner: jest.fn(() => origOwner),
isActive: jest.fn(() => true),
owner: jest.fn(() => origOwner),
tile: jest.fn(() => 20011),
} as any;
dstPort = {
tile: jest.fn(() => 30015), // 15x15
owner: jest.fn(() => dstOwner),
isActive: jest.fn(() => true),
owner: jest.fn(() => dstOwner),
tile: jest.fn(() => 30015), // 15x15
} as any;
tradeShip = {
isActive: jest.fn(() => true),
owner: jest.fn(() => origOwner),
move: jest.fn(),
setTargetUnit: jest.fn(),
setSafeFromPirates: jest.fn(),
delete: jest.fn(),
isActive: jest.fn(() => true),
move: jest.fn(),
owner: jest.fn(() => origOwner),
setSafeFromPirates: jest.fn(),
setTargetUnit: jest.fn(),
tile: jest.fn(() => 2001),
} as any;
tradeShipExecution = new TradeShipExecution(origOwner, srcPort, dstPort);
tradeShipExecution.init(game, 0);
tradeShipExecution["pathFinder"] = {
nextTile: jest.fn(() => ({ type: 0, node: 2001 })),
nextTile: jest.fn(() => ({ node: 2001, type: 0 })),
} as any;
tradeShipExecution["tradeShip"] = tradeShip;
});
@@ -112,7 +112,7 @@ describe("TradeShipExecution", () => {
it("should complete trade and award gold", () => {
tradeShipExecution["pathFinder"] = {
nextTile: jest.fn(() => ({ type: 2, node: 2001 })),
nextTile: jest.fn(() => ({ node: 2001, type: 2 })),
} as any;
tradeShipExecution.tick(1);
expect(tradeShip.delete).toHaveBeenCalledWith(false);
+1 -1
View File
@@ -2,9 +2,9 @@ import { Cluster, TrainStation } from "../../../src/core/game/TrainStation";
const createMockStation = (id: string): jest.Mocked<TrainStation> => {
return {
getCluster: jest.fn(() => null),
id,
setCluster: jest.fn(),
getCluster: jest.fn(() => null),
} as any;
};
+1 -1
View File
@@ -21,8 +21,8 @@ describe("GameImpl", () => {
beforeEach(async () => {
game = await setup("ocean_and_land", {
infiniteGold: true,
instantBuild: true,
infiniteTroops: true,
instantBuild: true,
});
const attackerInfo = new PlayerInfo(
"attacker dude",
+12 -12
View File
@@ -11,17 +11,17 @@ const createMockStation = (unitId: number): any => {
const cluster = new Cluster();
const railroads = new Set<Railroad>();
return {
addRailroad: jest.fn(),
clearRailroads: jest.fn(),
getCluster: jest.fn(() => cluster),
getRailroads: jest.fn(() => railroads),
neighbors: jest.fn(() => []),
setCluster: jest.fn(),
tile: jest.fn(),
unit: {
id: unitId,
setTrainStation: jest.fn(),
},
tile: jest.fn(),
neighbors: jest.fn(() => []),
getCluster: jest.fn(() => cluster),
setCluster: jest.fn(),
addRailroad: jest.fn(),
getRailroads: jest.fn(() => railroads),
clearRailroads: jest.fn(),
};
};
@@ -55,22 +55,22 @@ describe("RailNetworkImpl", () => {
beforeEach(() => {
stationManager = {
addStation: jest.fn(),
removeStation: jest.fn(),
findStation: jest.fn(),
getAll: jest.fn(() => new Set()),
removeStation: jest.fn(),
};
pathService = {
findTilePath: jest.fn(() => [0]),
findStationsPath: jest.fn(() => [0]),
findTilePath: jest.fn(() => [0]),
};
game = {
nearbyUnits: jest.fn(() => []),
addExecution: jest.fn(),
config: () => ({
railroadMaxSize: () => 100,
trainStationMaxRange: () => 80,
trainStationMinRange: () => 10,
railroadMaxSize: () => 100,
}),
nearbyUnits: jest.fn(() => []),
};
network = new RailNetworkImpl(game, stationManager, pathService);
@@ -153,7 +153,7 @@ describe("RailNetworkImpl", () => {
neighborStation.getCluster = jest.fn(() => cluster);
cluster.has = jest.fn(() => false);
const neighborUnit = { unit: neighborStation.unit, distSquared: 20 };
const neighborUnit = { distSquared: 20, unit: neighborStation.unit };
game.nearbyUnits.mockReturnValue([neighborUnit]);
stationManager.findStation.mockReturnValue(neighborStation);
+9 -9
View File
@@ -14,34 +14,34 @@ describe("TrainStation", () => {
beforeEach(() => {
game = {
ticks: jest.fn().mockReturnValue(123),
addExecution: jest.fn(),
addUpdate: jest.fn(),
config: jest.fn().mockReturnValue({
trainGold: (isFriendly: boolean) =>
isFriendly ? BigInt(1000) : BigInt(500),
}),
addUpdate: jest.fn(),
addExecution: jest.fn(),
ticks: jest.fn().mockReturnValue(123),
} as any;
player = {
addGold: jest.fn(),
id: 1,
canTrade: jest.fn().mockReturnValue(true),
id: 1,
isFriendly: jest.fn().mockReturnValue(false),
} as any;
unit = {
owner: jest.fn().mockReturnValue(player),
isActive: jest.fn().mockReturnValue(true),
level: jest.fn().mockReturnValue(1),
owner: jest.fn().mockReturnValue(player),
tile: jest.fn().mockReturnValue({ x: 0, y: 0 }),
type: jest.fn(),
isActive: jest.fn().mockReturnValue(true),
} as any;
trainExecution = {
level: jest.fn(),
loadCargo: jest.fn(),
owner: jest.fn().mockReturnValue(player),
level: jest.fn(),
} as any;
});
@@ -82,7 +82,7 @@ describe("TrainStation", () => {
it("adds and retrieves neighbors", () => {
const stationA = new TrainStation(game, unit);
const stationB = new TrainStation(game, unit);
const railRoad = { from: stationA, to: stationB, tiles: [] } as any;
const railRoad = { from: stationA, tiles: [], to: stationB } as any;
stationA.addRailroad(railRoad);
@@ -96,8 +96,8 @@ describe("TrainStation", () => {
const railRoad = {
from: stationA,
to: stationB,
tiles: [{ x: 1, y: 1 }],
to: stationB,
} as any;
stationA.addRailroad(railRoad);