Update draw and play functions for player indexing
Added tests covering drawCards(state, playerIndex, count) and playCard(state, playerIndex, handIndex, targetIndex) signatures. Also tests the per-player endTurn path with playersReady tracking.
This commit is contained in:
parent
b2056d8368
commit
86287a30c2
1 changed files with 66 additions and 0 deletions
|
|
@ -152,3 +152,69 @@ describe("createCombatState - multi player/enemy", () => {
|
|||
expect(state.enemies[0].instanceId).not.toBe(state.enemies[1].instanceId);
|
||||
});
|
||||
});
|
||||
|
||||
describe("drawCards - indexed player", () => {
|
||||
test("draws for player 1 leaving player 0 unchanged", () => {
|
||||
const state = createCombatState(["ironclad", "ironclad"], ["jaw_worm"]);
|
||||
const next = drawCards(state, 1, 3);
|
||||
expect(next.players[0].hand).toHaveLength(0);
|
||||
expect(next.players[1].hand).toHaveLength(3);
|
||||
expect(next.players[1].drawPile).toHaveLength(7);
|
||||
});
|
||||
|
||||
test("draws for player 0 explicitly", () => {
|
||||
const state = createCombatState(["ironclad", "ironclad"], ["jaw_worm"]);
|
||||
const next = drawCards(state, 0, 5);
|
||||
expect(next.players[0].hand).toHaveLength(5);
|
||||
expect(next.players[1].hand).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("playCard - indexed player and enemy", () => {
|
||||
test("player 1 plays a card targeting enemy 0", () => {
|
||||
let state = createCombatState(["ironclad", "ironclad"], ["jaw_worm"]);
|
||||
state = drawCards(state, 1, 5);
|
||||
const cardIndex = state.players[1].hand.indexOf("strike_r");
|
||||
const next = playCard(state, 1, cardIndex, 0);
|
||||
expect(next.players[1].energy).toBe(2);
|
||||
expect(next.players[1].hand).toHaveLength(4);
|
||||
// player 0 unaffected
|
||||
expect(next.players[0].energy).toBe(3);
|
||||
});
|
||||
|
||||
test("playCard with player index returns null if not enough energy", () => {
|
||||
let state = createCombatState(["ironclad", "ironclad"], ["jaw_worm"]);
|
||||
state = drawCards(state, 1, 5);
|
||||
const zeroEnergy = { ...state.players[1], energy: 0 };
|
||||
state = {
|
||||
...state,
|
||||
players: [state.players[0], zeroEnergy],
|
||||
};
|
||||
const cardIndex = state.players[1].hand.indexOf("strike_r");
|
||||
const result = playCard(state, 1, cardIndex, 0);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("endTurn - indexed player", () => {
|
||||
test("endTurn with playerIndex discards hand and marks player ready", () => {
|
||||
let state = createCombatState(["ironclad", "ironclad"], ["jaw_worm"]);
|
||||
state = drawCards(state, 0, 5);
|
||||
const next = endTurn(state, 0);
|
||||
expect(next.players[0].hand).toHaveLength(0);
|
||||
expect(next.players[0].discardPile.length).toBeGreaterThan(0);
|
||||
expect(next.combat.playersReady).toContain(0);
|
||||
// phase stays player_turn until all players ready
|
||||
expect(next.combat.phase).toBe("player_turn");
|
||||
});
|
||||
|
||||
test("phase switches to enemy_turn when all players ready", () => {
|
||||
let state = createCombatState(["ironclad", "ironclad"], ["jaw_worm"]);
|
||||
state = drawCards(state, 0, 3);
|
||||
state = drawCards(state, 1, 3);
|
||||
state = endTurn(state, 0);
|
||||
const next = endTurn(state, 1);
|
||||
expect(next.combat.phase).toBe("enemy_turn");
|
||||
expect(next.combat.playersReady).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue