- ${[2, 3, 4, 5, 6, 7].map(
+ ${["Duos", 2, 3, 4, 5, 6, 7].map(
(o) => html`
{
const config = await getConfig(gameStart.config, null);
const gameMap = await loadGameMap(gameStart.config.gameMap);
- const game = createGame(
- gameStart.players.map(
- (p) =>
- new PlayerInfo(
- p.flag,
- p.clientID == clientID
- ? sanitize(p.username)
- : fixProfaneUsername(sanitize(p.username)),
- PlayerType.Human,
- p.clientID,
- p.playerID,
- ),
- ),
+ const random = new PseudoRandom(simpleHash(gameStart.gameID));
+
+ const humans = gameStart.players.map(
+ (p) =>
+ new PlayerInfo(
+ p.flag,
+ p.clientID == clientID
+ ? sanitize(p.username)
+ : fixProfaneUsername(sanitize(p.username)),
+ PlayerType.Human,
+ p.clientID,
+ p.playerID,
+ ),
+ );
+
+ const nations = gameStart.config.disableNPCs
+ ? []
+ : gameMap.nationMap.nations.map(
+ (n) =>
+ new Nation(
+ new Cell(n.coordinates[0], n.coordinates[1]),
+ n.strength,
+ new PlayerInfo(
+ n.flag || "",
+ n.name,
+ PlayerType.FakeHuman,
+ null,
+ random.nextID(),
+ ),
+ ),
+ );
+
+ const game: Game = createGame(
+ humans,
+ nations,
gameMap.gameMap,
gameMap.miniGameMap,
- gameMap.nationMap,
config,
);
+
const gr = new GameRunner(
- game as Game,
+ game,
new Executor(game, gameStart.gameID, clientID),
callBack,
);
diff --git a/src/core/Schemas.ts b/src/core/Schemas.ts
index 3fb370804..94fa5e369 100644
--- a/src/core/Schemas.ts
+++ b/src/core/Schemas.ts
@@ -2,11 +2,11 @@ import { z } from "zod";
import {
AllPlayers,
Difficulty,
+ Duos,
GameMapType,
GameMode,
GameType,
PlayerType,
- Team,
UnitType,
} from "./game/Game";
@@ -121,9 +121,11 @@ const GameConfigSchema = z.object({
infiniteTroops: z.boolean(),
instantBuild: z.boolean(),
maxPlayers: z.number().optional(),
- numPlayerTeams: z.number().optional(),
+ playerTeams: z.union([z.number().optional(), z.literal(Duos)]),
});
+export const TeamSchema = z.string();
+
const SafeString = z
.string()
.regex(
@@ -364,7 +366,7 @@ const ClientBaseMessageSchema = z.object({
export const ClientSendWinnerSchema = ClientBaseMessageSchema.extend({
type: z.literal("winner"),
- winner: ID.or(z.nativeEnum(Team)).nullable(),
+ winner: z.union([ID, TeamSchema]).nullable(),
allPlayersStats: AllPlayersStatsSchema,
winnerType: z.enum(["player", "team"]),
});
@@ -425,10 +427,7 @@ export const GameRecordSchema = z.object({
date: SafeString,
num_turns: z.number(),
turns: z.array(TurnSchema),
- winner: z
- .union([ID, z.nativeEnum(Team)])
- .nullable()
- .optional(),
+ winner: z.union([ID, SafeString]).nullable().optional(),
winnerType: z.enum(["player", "team"]).nullable().optional(),
allPlayersStats: z.record(ID, PlayerStatsSchema),
version: z.enum(["v0.0.1"]),
diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts
index 64ef95be0..777ff8ec9 100644
--- a/src/core/configuration/Config.ts
+++ b/src/core/configuration/Config.ts
@@ -2,6 +2,7 @@ import { Colord } from "colord";
import { GameConfig, GameID } from "../Schemas";
import {
Difficulty,
+ Duos,
Game,
GameMapType,
Gold,
@@ -67,7 +68,7 @@ export interface Config {
instantBuild(): boolean;
numSpawnPhaseTurns(): number;
userSettings(): UserSettings;
- numPlayerTeams(): number;
+ playerTeams(): number | typeof Duos;
startManpower(playerInfo: PlayerInfo): number;
populationIncreaseRate(player: Player | PlayerView): number;
diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts
index c65288115..211ade9e6 100644
--- a/src/core/configuration/DefaultConfig.ts
+++ b/src/core/configuration/DefaultConfig.ts
@@ -1,5 +1,6 @@
import {
Difficulty,
+ Duos,
Game,
GameMapType,
GameMode,
@@ -203,12 +204,14 @@ export class DefaultConfig implements Config {
defensePostDefenseBonus(): number {
return 5;
}
- numPlayerTeams(): number {
- return this._gameConfig.numPlayerTeams ?? 0;
+ playerTeams(): number | typeof Duos {
+ return this._gameConfig.playerTeams ?? 0;
}
+
spawnNPCs(): boolean {
return !this._gameConfig.disableNPCs;
}
+
disableNukes(): boolean {
return this._gameConfig.disableNukes;
}
diff --git a/src/core/configuration/PastelTheme.ts b/src/core/configuration/PastelTheme.ts
index 83c56c7ea..9c4ac5d6c 100644
--- a/src/core/configuration/PastelTheme.ts
+++ b/src/core/configuration/PastelTheme.ts
@@ -1,7 +1,7 @@
import { Colord, colord } from "colord";
import { PseudoRandom } from "../PseudoRandom";
import { simpleHash } from "../Util";
-import { PlayerType, Team, TerrainType } from "../game/Game";
+import { ColoredTeams, PlayerType, Team, TerrainType } from "../game/Game";
import { GameMap, TileRef } from "../game/GameMap";
import { PlayerView } from "../game/GameView";
import {
@@ -43,24 +43,25 @@ export const pastelTheme = new (class implements Theme {
teamColor(team: Team): Colord {
switch (team) {
- case Team.Blue:
+ case ColoredTeams.Blue:
return blue;
- case Team.Red:
+ case ColoredTeams.Red:
return red;
- case Team.Teal:
+ case ColoredTeams.Teal:
return teal;
- case Team.Purple:
+ case ColoredTeams.Purple:
return purple;
- case Team.Yellow:
+ case ColoredTeams.Yellow:
return yellow;
- case Team.Orange:
+ case ColoredTeams.Orange:
return orange;
- case Team.Green:
+ case ColoredTeams.Green:
return green;
- case Team.Bot:
+ case ColoredTeams.Bot:
return botColor;
+ default:
+ return humanColors[simpleHash(team) % humanColors.length];
}
- throw new Error(`Missing color for ${team}`);
}
territoryColor(player: PlayerView): Colord {
diff --git a/src/core/configuration/PastelThemeDark.ts b/src/core/configuration/PastelThemeDark.ts
index efc6bcd67..bc9dd8ddf 100644
--- a/src/core/configuration/PastelThemeDark.ts
+++ b/src/core/configuration/PastelThemeDark.ts
@@ -1,7 +1,7 @@
import { Colord, colord } from "colord";
import { PseudoRandom } from "../PseudoRandom";
import { simpleHash } from "../Util";
-import { PlayerType, Team, TerrainType } from "../game/Game";
+import { ColoredTeams, PlayerType, Team, TerrainType } from "../game/Game";
import { GameMap, TileRef } from "../game/GameMap";
import { PlayerView } from "../game/GameView";
import {
@@ -43,24 +43,25 @@ export const pastelThemeDark = new (class implements Theme {
teamColor(team: Team): Colord {
switch (team) {
- case Team.Blue:
+ case ColoredTeams.Blue:
return blue;
- case Team.Red:
+ case ColoredTeams.Red:
return red;
- case Team.Teal:
+ case ColoredTeams.Teal:
return teal;
- case Team.Purple:
+ case ColoredTeams.Purple:
return purple;
- case Team.Yellow:
+ case ColoredTeams.Yellow:
return yellow;
- case Team.Orange:
+ case ColoredTeams.Orange:
return orange;
- case Team.Green:
+ case ColoredTeams.Green:
return green;
- case Team.Bot:
+ case ColoredTeams.Bot:
return botColor;
+ default:
+ return humanColors[simpleHash(team) % humanColors.length];
}
- throw new Error(`Missing color for ${team}`);
}
territoryColor(player: PlayerView): Colord {
diff --git a/src/core/execution/ExecutionManager.ts b/src/core/execution/ExecutionManager.ts
index 83795f90d..73bfb97e9 100644
--- a/src/core/execution/ExecutionManager.ts
+++ b/src/core/execution/ExecutionManager.ts
@@ -1,4 +1,4 @@
-import { Execution, Game, PlayerInfo, PlayerType } from "../game/Game";
+import { Execution, Game } from "../game/Game";
import { PseudoRandom } from "../PseudoRandom";
import { ClientID, GameID, Intent, Turn } from "../Schemas";
import { simpleHash } from "../Util";
@@ -120,19 +120,7 @@ export class Executor {
fakeHumanExecutions(): Execution[] {
const execs = [];
for (const nation of this.mg.nations()) {
- execs.push(
- new FakeHumanExecution(
- this.gameID,
- new PlayerInfo(
- nation.flag || "",
- nation.name,
- PlayerType.FakeHuman,
- null,
- this.random.nextID(),
- nation,
- ),
- ),
- );
+ execs.push(new FakeHumanExecution(this.gameID, nation));
}
return execs;
}
diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts
index 44e73fd20..c7e6953f0 100644
--- a/src/core/execution/FakeHumanExecution.ts
+++ b/src/core/execution/FakeHumanExecution.ts
@@ -4,9 +4,9 @@ import {
Difficulty,
Execution,
Game,
+ Nation,
Player,
PlayerID,
- PlayerInfo,
PlayerType,
Relation,
TerrainType,
@@ -46,10 +46,10 @@ export class FakeHumanExecution implements Execution {
constructor(
gameID: GameID,
- private playerInfo: PlayerInfo,
+ private nation: Nation,
) {
this.random = new PseudoRandom(
- simpleHash(playerInfo.id) + simpleHash(gameID),
+ simpleHash(nation.playerInfo.id) + simpleHash(gameID),
);
this.attackRate = this.random.nextInt(40, 80);
this.attackTick = this.random.nextInt(0, this.attackRate);
@@ -110,15 +110,17 @@ export class FakeHumanExecution implements Execution {
if (this.mg.inSpawnPhase()) {
const rl = this.randomLand();
if (rl == null) {
- consolex.warn(`cannot spawn ${this.playerInfo.name}`);
+ consolex.warn(`cannot spawn ${this.nation.playerInfo.name}`);
return;
}
- this.mg.addExecution(new SpawnExecution(this.playerInfo, rl));
+ this.mg.addExecution(new SpawnExecution(this.nation.playerInfo, rl));
return;
}
if (this.player == null) {
- this.player = this.mg.players().find((p) => p.id() == this.playerInfo.id);
+ this.player = this.mg
+ .players()
+ .find((p) => p.id() == this.nation.playerInfo.id);
if (this.player == null) {
return;
}
@@ -553,7 +555,7 @@ export class FakeHumanExecution implements Execution {
let tries = 0;
while (tries < 50) {
tries++;
- const cell = this.playerInfo.nation.cell;
+ const cell = this.nation.spawnCell;
const x = this.random.nextInt(cell.x - delta, cell.x + delta);
const y = this.random.nextInt(cell.y - delta, cell.y + delta);
if (!this.mg.isValidCoord(x, y)) {
diff --git a/src/core/execution/WinCheckExecution.ts b/src/core/execution/WinCheckExecution.ts
index a18521998..e40e3f0b7 100644
--- a/src/core/execution/WinCheckExecution.ts
+++ b/src/core/execution/WinCheckExecution.ts
@@ -1,5 +1,12 @@
import { GameEvent } from "../EventBus";
-import { Execution, Game, GameMode, Player, Team } from "../game/Game";
+import {
+ ColoredTeams,
+ Execution,
+ Game,
+ GameMode,
+ Player,
+ Team,
+} from "../game/Game";
export class WinEvent implements GameEvent {
constructor(public readonly winner: Player) {}
@@ -66,7 +73,7 @@ export class WinCheckExecution implements Execution {
this.mg.numLandTiles() - this.mg.numTilesWithFallout();
const percentage = (max[1] / numTilesWithoutFallout) * 100;
if (percentage > this.mg.config().percentageTilesOwnedToWin()) {
- if (max[0] == Team.Bot) return;
+ if (max[0] == ColoredTeams.Bot) return;
this.mg.setWinner(max[0], this.mg.stats().stats());
console.log(`${max[0]} has won the game`);
this.active = false;
diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts
index ecbab2ecf..17cc19e63 100644
--- a/src/core/game/Game.ts
+++ b/src/core/game/Game.ts
@@ -37,16 +37,20 @@ export enum Difficulty {
Impossible = "Impossible",
}
-export enum Team {
- Red = "Red",
- Blue = "Blue",
- Teal = "Teal",
- Purple = "Purple",
- Yellow = "Yellow",
- Orange = "Orange",
- Green = "Green",
- Bot = "Bot",
-}
+export type Team = string;
+
+export const Duos = "Duos" as const;
+
+export const ColoredTeams: Record
= {
+ Red: "Red",
+ Blue: "Blue",
+ Teal: "Teal",
+ Purple: "Purple",
+ Yellow: "Yellow",
+ Orange: "Orange",
+ Green: "Green",
+ Bot: "Bot",
+} as const;
export enum GameMapType {
World = "World",
@@ -158,10 +162,9 @@ export enum Relation {
export class Nation {
constructor(
- public readonly flag: string,
- public readonly name: string,
- public readonly cell: Cell,
+ public readonly spawnCell: Cell,
public readonly strength: number,
+ public readonly playerInfo: PlayerInfo,
) {}
}
diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts
index 772cf7d23..ccf269688 100644
--- a/src/core/game/GameImpl.ts
+++ b/src/core/game/GameImpl.ts
@@ -8,6 +8,8 @@ import {
Alliance,
AllianceRequest,
Cell,
+ ColoredTeams,
+ Duos,
EmojiMessage,
Execution,
Game,
@@ -32,19 +34,18 @@ import { PlayerImpl } from "./PlayerImpl";
import { Stats } from "./Stats";
import { StatsImpl } from "./StatsImpl";
import { assignTeams } from "./TeamAssignment";
-import { NationMap } from "./TerrainMapLoader";
import { TerraNulliusImpl } from "./TerraNulliusImpl";
import { UnitGrid } from "./UnitGrid";
import { UnitImpl } from "./UnitImpl";
export function createGame(
humans: PlayerInfo[],
+ nations: Nation[],
gameMap: GameMap,
miniGameMap: GameMap,
- nationMap: NationMap,
config: Config,
): Game {
- return new GameImpl(humans, gameMap, miniGameMap, nationMap, config);
+ return new GameImpl(humans, nations, gameMap, miniGameMap, config);
}
export type CellString = string;
@@ -54,8 +55,6 @@ export class GameImpl implements Game {
private unInitExecs: Execution[] = [];
- private nations_: Nation[] = [];
-
_players: Map = new Map();
_playersBySmallID = [];
@@ -75,51 +74,62 @@ export class GameImpl implements Game {
private _stats: StatsImpl = new StatsImpl();
- private playerTeams: Team[] = [Team.Red, Team.Blue];
- private botTeam: Team = Team.Bot;
+ private playerTeams: Team[] = [ColoredTeams.Red, ColoredTeams.Blue];
+ private botTeam: Team = ColoredTeams.Bot;
constructor(
private _humans: PlayerInfo[],
+ private _nations: Nation[],
private _map: GameMap,
private miniGameMap: GameMap,
- nationMap: NationMap,
private _config: Config,
) {
this._terraNullius = new TerraNulliusImpl();
this._width = _map.width();
this._height = _map.height();
- this.nations_ = nationMap.nations.map(
- (n) =>
- new Nation(
- n.flag || "",
- n.name,
- new Cell(n.coordinates[0], n.coordinates[1]),
- n.strength,
- ),
- );
this.unitGrid = new UnitGrid(this._map);
if (_config.gameConfig().gameMode === GameMode.Team) {
- const numPlayerTeams = _config.numPlayerTeams();
+ this.populateTeams();
+ }
+ this.addPlayers();
+ }
+
+ private populateTeams() {
+ if (this._config.playerTeams() === Duos) {
+ this.playerTeams = [];
+ const numTeams = Math.ceil(
+ (this._humans.length + this._nations.length) / 2,
+ );
+ for (let i = 0; i < numTeams; i++) {
+ this.playerTeams.push("Team " + (i + 1));
+ }
+ } else {
+ const numPlayerTeams = this._config.playerTeams() as number;
if (numPlayerTeams < 2)
throw new Error(`Too few teams: ${numPlayerTeams}`);
- if (numPlayerTeams >= 3) this.playerTeams.push(Team.Teal);
- if (numPlayerTeams >= 4) this.playerTeams.push(Team.Purple);
- if (numPlayerTeams >= 5) this.playerTeams.push(Team.Yellow);
- if (numPlayerTeams >= 6) this.playerTeams.push(Team.Orange);
- if (numPlayerTeams >= 7) this.playerTeams.push(Team.Green);
+ if (numPlayerTeams >= 3) this.playerTeams.push(ColoredTeams.Teal);
+ if (numPlayerTeams >= 4) this.playerTeams.push(ColoredTeams.Purple);
+ if (numPlayerTeams >= 5) this.playerTeams.push(ColoredTeams.Yellow);
+ if (numPlayerTeams >= 6) this.playerTeams.push(ColoredTeams.Orange);
+ if (numPlayerTeams >= 7) this.playerTeams.push(ColoredTeams.Green);
if (numPlayerTeams >= 8)
throw new Error(`Too many teams: ${numPlayerTeams}`);
}
- this.addHumans();
}
- private addHumans() {
+ private addPlayers() {
if (this.config().gameConfig().gameMode != GameMode.Team) {
this._humans.forEach((p) => this.addPlayer(p));
+ this._nations.forEach((n) => this.addPlayer(n.playerInfo));
return;
}
- const playerToTeam = assignTeams(this._humans, this.playerTeams);
+ const isDuos = this.config().gameConfig().playerTeams === Duos;
+ const allPlayers = [
+ ...this._humans,
+ ...this._nations.map((n) => n.playerInfo),
+ ];
+ const playerToTeam = assignTeams(allPlayers, this.playerTeams);
for (const [playerInfo, team] of playerToTeam.entries()) {
if (team == "kicked") {
console.warn(`Player ${playerInfo.name} was kicked from team`);
@@ -180,7 +190,7 @@ export class GameImpl implements Game {
return this.config().unitInfo(type);
}
nations(): Nation[] {
- return this.nations_;
+ return this._nations;
}
createAllianceRequest(requestor: Player, recipient: Player): AllianceRequest {
diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts
index ac27c845c..e3e60f972 100644
--- a/src/server/GameServer.ts
+++ b/src/server/GameServer.ts
@@ -95,8 +95,8 @@ export class GameServer {
if (gameConfig.gameMode != null) {
this.gameConfig.gameMode = gameConfig.gameMode;
}
- if (gameConfig.numPlayerTeams != null) {
- this.gameConfig.numPlayerTeams = gameConfig.numPlayerTeams;
+ if (gameConfig.playerTeams != null) {
+ this.gameConfig.playerTeams = gameConfig.playerTeams;
}
}
diff --git a/src/server/Master.ts b/src/server/Master.ts
index bc31cd120..b8695e634 100644
--- a/src/server/Master.ts
+++ b/src/server/Master.ts
@@ -252,7 +252,7 @@ async function schedulePublicGame(playlist: MapPlaylist) {
disableNPCs: gameMode == GameMode.Team,
disableNukes: false,
gameMode,
- numPlayerTeams,
+ playerTeams: numPlayerTeams,
bots: 400,
};
diff --git a/src/server/Worker.ts b/src/server/Worker.ts
index d8747ebb3..9285886a5 100644
--- a/src/server/Worker.ts
+++ b/src/server/Worker.ts
@@ -165,7 +165,7 @@ export function startWorker() {
disableNPCs: req.body.disableNPCs,
disableNukes: req.body.disableNukes,
gameMode: req.body.gameMode,
- numPlayerTeams: req.body.numPlayerTeams,
+ playerTeams: req.body.playerTeams,
});
res.status(200).json({ success: true });
}),
diff --git a/tests/TeamAssignment.test.ts b/tests/TeamAssignment.test.ts
index 340182e6f..331af56ef 100644
--- a/tests/TeamAssignment.test.ts
+++ b/tests/TeamAssignment.test.ts
@@ -1,7 +1,7 @@
-import { PlayerInfo, PlayerType, Team } from "../src/core/game/Game";
+import { ColoredTeams, PlayerInfo, PlayerType } from "../src/core/game/Game";
import { assignTeams } from "../src/core/game/TeamAssignment";
-const teams = [Team.Red, Team.Blue];
+const teams = [ColoredTeams.Red, ColoredTeams.Blue];
describe("assignTeams", () => {
const createPlayer = (id: string, clan?: string): PlayerInfo => {
@@ -27,10 +27,10 @@ describe("assignTeams", () => {
const result = assignTeams(players, teams);
// Check that players are assigned alternately
- expect(result.get(players[0])).toEqual(Team.Red);
- expect(result.get(players[1])).toEqual(Team.Blue);
- expect(result.get(players[2])).toEqual(Team.Red);
- expect(result.get(players[3])).toEqual(Team.Blue);
+ expect(result.get(players[0])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[1])).toEqual(ColoredTeams.Blue);
+ expect(result.get(players[2])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[3])).toEqual(ColoredTeams.Blue);
});
it("should keep clan members together on the same team", () => {
@@ -44,10 +44,10 @@ describe("assignTeams", () => {
const result = assignTeams(players, teams);
// Check that clan members are on the same team
- expect(result.get(players[0])).toEqual(Team.Red);
- expect(result.get(players[1])).toEqual(Team.Red);
- expect(result.get(players[2])).toEqual(Team.Blue);
- expect(result.get(players[3])).toEqual(Team.Blue);
+ expect(result.get(players[0])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[1])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[2])).toEqual(ColoredTeams.Blue);
+ expect(result.get(players[3])).toEqual(ColoredTeams.Blue);
});
it("should handle mixed clan and non-clan players", () => {
@@ -61,10 +61,10 @@ describe("assignTeams", () => {
const result = assignTeams(players, teams);
// Check that clan members are together and non-clan players balance teams
- expect(result.get(players[0])).toEqual(Team.Red);
- expect(result.get(players[1])).toEqual(Team.Red);
- expect(result.get(players[2])).toEqual(Team.Blue);
- expect(result.get(players[3])).toEqual(Team.Blue);
+ expect(result.get(players[0])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[1])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[2])).toEqual(ColoredTeams.Blue);
+ expect(result.get(players[3])).toEqual(ColoredTeams.Blue);
});
it("should kick players when teams are full", () => {
@@ -80,14 +80,14 @@ describe("assignTeams", () => {
const result = assignTeams(players, teams);
// Check that players are kicked when teams are full
- expect(result.get(players[0])).toEqual(Team.Red);
- expect(result.get(players[1])).toEqual(Team.Red);
- expect(result.get(players[2])).toEqual(Team.Red);
+ expect(result.get(players[0])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[1])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[2])).toEqual(ColoredTeams.Red);
expect(result.get(players[3])).toEqual("kicked");
- expect(result.get(players[4])).toEqual(Team.Blue);
- expect(result.get(players[5])).toEqual(Team.Blue);
+ expect(result.get(players[4])).toEqual(ColoredTeams.Blue);
+ expect(result.get(players[5])).toEqual(ColoredTeams.Blue);
});
it("should handle empty player list", () => {
@@ -98,7 +98,7 @@ describe("assignTeams", () => {
it("should handle single player", () => {
const players = [createPlayer("1")];
const result = assignTeams(players, teams);
- expect(result.get(players[0])).toEqual(Team.Red);
+ expect(result.get(players[0])).toEqual(ColoredTeams.Red);
});
it("should handle multiple clans with different sizes", () => {
@@ -114,12 +114,12 @@ describe("assignTeams", () => {
const result = assignTeams(players, teams);
// Check that larger clans are assigned first
- expect(result.get(players[0])).toEqual(Team.Red);
- expect(result.get(players[1])).toEqual(Team.Red);
- expect(result.get(players[2])).toEqual(Team.Red);
- expect(result.get(players[3])).toEqual(Team.Blue);
- expect(result.get(players[4])).toEqual(Team.Blue);
- expect(result.get(players[5])).toEqual(Team.Blue);
+ expect(result.get(players[0])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[1])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[2])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[3])).toEqual(ColoredTeams.Blue);
+ expect(result.get(players[4])).toEqual(ColoredTeams.Blue);
+ expect(result.get(players[5])).toEqual(ColoredTeams.Blue);
});
it("should distribute players among a larger number of teams", () => {
@@ -141,28 +141,28 @@ describe("assignTeams", () => {
];
const result = assignTeams(players, [
- Team.Red,
- Team.Blue,
- Team.Teal,
- Team.Purple,
- Team.Yellow,
- Team.Orange,
- Team.Green,
+ ColoredTeams.Red,
+ ColoredTeams.Blue,
+ ColoredTeams.Teal,
+ ColoredTeams.Purple,
+ ColoredTeams.Yellow,
+ ColoredTeams.Orange,
+ ColoredTeams.Green,
]);
- expect(result.get(players[0])).toEqual(Team.Red);
- expect(result.get(players[1])).toEqual(Team.Red);
+ expect(result.get(players[0])).toEqual(ColoredTeams.Red);
+ expect(result.get(players[1])).toEqual(ColoredTeams.Red);
expect(result.get(players[2])).toEqual("kicked");
- expect(result.get(players[3])).toEqual(Team.Blue);
- expect(result.get(players[4])).toEqual(Team.Blue);
- expect(result.get(players[5])).toEqual(Team.Teal);
- expect(result.get(players[6])).toEqual(Team.Purple);
- expect(result.get(players[7])).toEqual(Team.Yellow);
- expect(result.get(players[8])).toEqual(Team.Orange);
- expect(result.get(players[9])).toEqual(Team.Green);
- expect(result.get(players[10])).toEqual(Team.Teal);
- expect(result.get(players[11])).toEqual(Team.Purple);
- expect(result.get(players[12])).toEqual(Team.Yellow);
- expect(result.get(players[13])).toEqual(Team.Orange);
+ expect(result.get(players[3])).toEqual(ColoredTeams.Blue);
+ expect(result.get(players[4])).toEqual(ColoredTeams.Blue);
+ expect(result.get(players[5])).toEqual(ColoredTeams.Teal);
+ expect(result.get(players[6])).toEqual(ColoredTeams.Purple);
+ expect(result.get(players[7])).toEqual(ColoredTeams.Yellow);
+ expect(result.get(players[8])).toEqual(ColoredTeams.Orange);
+ expect(result.get(players[9])).toEqual(ColoredTeams.Green);
+ expect(result.get(players[10])).toEqual(ColoredTeams.Teal);
+ expect(result.get(players[11])).toEqual(ColoredTeams.Purple);
+ expect(result.get(players[12])).toEqual(ColoredTeams.Yellow);
+ expect(result.get(players[13])).toEqual(ColoredTeams.Orange);
});
});
diff --git a/tests/util/Setup.ts b/tests/util/Setup.ts
index 6e3c244bb..7f8b98a83 100644
--- a/tests/util/Setup.ts
+++ b/tests/util/Setup.ts
@@ -18,7 +18,6 @@ export async function setup(mapName: string, _gameConfig: GameConfig = {}) {
const miniGameMap = await genTerrainFromBin(
String.fromCharCode.apply(null, miniMap),
);
- const nationMap = { nations: [] };
// Configure the game
const serverConfig = new TestServerConfig();
@@ -36,5 +35,5 @@ export async function setup(mapName: string, _gameConfig: GameConfig = {}) {
const config = new TestConfig(serverConfig, gameConfig, new UserSettings());
// Create and return the game
- return createGame([], gameMap, miniGameMap, nationMap, config); // TODO: !!!
+ return createGame([], [], gameMap, miniGameMap, config);
}