Create ranked type enum, last person not afk wins in 1v1 (#2892)

## Description:

* Add RankedType enum, for now it's just 1v1
* Add new method to MapPlaylist to create 1v1 game config
* Update WinCheck so the last player is declared a winner on 1v1.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

evan
This commit is contained in:
Evan
2026-01-13 19:48:14 -08:00
committed by GitHub
parent 247c78151c
commit 42c944c9cc
6 changed files with 275 additions and 6 deletions
+215 -1
View File
@@ -4,8 +4,9 @@ import {
GameMode,
PlayerInfo,
PlayerType,
RankedType,
} from "../../../src/core/game/Game";
import { setup } from "../../util/Setup";
import { playerInfo, setup } from "../../util/Setup";
describe("WinCheckExecution", () => {
let mg: any;
@@ -369,3 +370,216 @@ describe("WinCheckExecution - Nation Winners", () => {
expect(winCheck.isActive()).toBe(true);
});
});
describe("WinCheckExecution - 1v1 Ranked Mode", () => {
test("should set winner when only one human remains connected", async () => {
// Setup game with 1v1 ranked mode and two human players
const game = await setup(
"big_plains",
{
infiniteGold: true,
gameMode: GameMode.FFA,
instantBuild: true,
rankedType: RankedType.OneVOne,
},
[
playerInfo("Player1", PlayerType.Human),
playerInfo("Player2", PlayerType.Human),
],
);
const human1 = game.player("Player1");
const human2 = game.player("Player2");
// Skip spawn phase
while (game.inSpawnPhase()) {
game.executeNextTick();
}
// Assign some territory to both players
let human1Count = 0;
let human2Count = 0;
game.map().forEachTile((tile) => {
if (!game.map().isLand(tile)) return;
if (human1Count < 10) {
human1.conquer(tile);
human1Count++;
} else if (human2Count < 10) {
human2.conquer(tile);
human2Count++;
}
});
// Mark player 2 as disconnected
human2.markDisconnected(true);
// Mock setWinner to capture calls
const setWinnerSpy = vi.fn();
game.setWinner = setWinnerSpy;
// Initialize and run win check
const winCheck = new WinCheckExecution();
winCheck.init(game, 0);
winCheck.checkWinnerFFA();
// Verify the remaining connected human is declared winner
expect(setWinnerSpy).toHaveBeenCalledWith(human1, expect.anything());
expect(winCheck.isActive()).toBe(false);
});
test("should not set winner when multiple humans are still connected", async () => {
// Setup game with 1v1 ranked mode and two human players
const game = await setup(
"big_plains",
{
infiniteGold: true,
gameMode: GameMode.FFA,
instantBuild: true,
rankedType: RankedType.OneVOne,
},
[
playerInfo("Player1", PlayerType.Human),
playerInfo("Player2", PlayerType.Human),
],
);
const human1 = game.player("Player1");
const human2 = game.player("Player2");
// Skip spawn phase
while (game.inSpawnPhase()) {
game.executeNextTick();
}
// Assign territory to both players
let human1Count = 0;
let human2Count = 0;
game.map().forEachTile((tile) => {
if (!game.map().isLand(tile)) return;
if (human1Count < 10) {
human1.conquer(tile);
human1Count++;
} else if (human2Count < 10) {
human2.conquer(tile);
human2Count++;
}
});
// Both players remain connected
expect(human1.isDisconnected()).toBe(false);
expect(human2.isDisconnected()).toBe(false);
// Mock setWinner to capture calls
const setWinnerSpy = vi.fn();
game.setWinner = setWinnerSpy;
// Initialize and run win check
const winCheck = new WinCheckExecution();
winCheck.init(game, 0);
winCheck.checkWinnerFFA();
// Verify no winner declared yet (both players still connected)
expect(setWinnerSpy).not.toHaveBeenCalled();
expect(winCheck.isActive()).toBe(true);
});
test("should not set winner when no humans remain connected", async () => {
// Setup game with 1v1 ranked mode and two human players
const game = await setup(
"big_plains",
{
infiniteGold: true,
gameMode: GameMode.FFA,
instantBuild: true,
rankedType: RankedType.OneVOne,
},
[
playerInfo("Player1", PlayerType.Human),
playerInfo("Player2", PlayerType.Human),
],
);
const human1 = game.player("Player1");
const human2 = game.player("Player2");
// Skip spawn phase
while (game.inSpawnPhase()) {
game.executeNextTick();
}
// Both players disconnect
human1.markDisconnected(true);
human2.markDisconnected(true);
// Mock setWinner to capture calls
const setWinnerSpy = vi.fn();
game.setWinner = setWinnerSpy;
// Initialize and run win check
const winCheck = new WinCheckExecution();
winCheck.init(game, 0);
winCheck.checkWinnerFFA();
// Verify no winner declared (no connected humans)
expect(setWinnerSpy).not.toHaveBeenCalled();
expect(winCheck.isActive()).toBe(true);
});
test("should ignore bots and nations in 1v1 ranked mode", async () => {
// Setup game with 1v1 ranked mode, one human, one bot, and one nation
const game = await setup(
"big_plains",
{
infiniteGold: true,
gameMode: GameMode.FFA,
instantBuild: true,
rankedType: RankedType.OneVOne,
},
[
playerInfo("HumanPlayer", PlayerType.Human),
playerInfo("BotPlayer", PlayerType.Bot),
playerInfo("NationPlayer", PlayerType.Nation),
],
);
const human = game.player("HumanPlayer");
const bot = game.player("BotPlayer");
const nation = game.player("NationPlayer");
// Skip spawn phase
while (game.inSpawnPhase()) {
game.executeNextTick();
}
// Assign territory to all players
let humanCount = 0;
let botCount = 0;
let nationCount = 0;
game.map().forEachTile((tile) => {
if (!game.map().isLand(tile)) return;
if (humanCount < 10) {
human.conquer(tile);
humanCount++;
} else if (botCount < 10) {
bot.conquer(tile);
botCount++;
} else if (nationCount < 10) {
nation.conquer(tile);
nationCount++;
}
});
// Mock setWinner to capture calls
const setWinnerSpy = vi.fn();
game.setWinner = setWinnerSpy;
// Initialize and run win check
const winCheck = new WinCheckExecution();
winCheck.init(game, 0);
winCheck.checkWinnerFFA();
// Verify human is declared winner (only one human player)
expect(setWinnerSpy).toHaveBeenCalledWith(human, expect.anything());
expect(winCheck.isActive()).toBe(false);
});
});