Skip to content

Commit 0c155be

Browse files
committed
allow shout TOCMs and add test for that
1 parent 98af372 commit 0c155be

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

src/conventions/h-group/interpret-discard.js

+25-23
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,30 @@ export function interpret_discard(game, action) {
269269
state.dda = state.deck[order].identity();
270270
}
271271
}
272-
272+
// Check if a Trash Order Chop Move happened.
273+
if (game.level >= LEVEL.TRASH_PUSH && !state.inEndgame()) {
274+
const leftmost_kt = before_trash.sort((a, b) => b - a)[0];
275+
if (order !== leftmost_kt) {
276+
// check for the Shout Trash Order cm
277+
const shout = (common.thinksPlayables(state, playerIndex).length) > 0 ? 1 : 0;
278+
const players_after = before_trash.indexOf(order) + shout;
279+
// make sure the discarded card is actually known trash
280+
if (players_after === -1 || players_after >= game.players.length) {
281+
resolve_discard(game, action, DISCARD_INTERP.NONE);
282+
return game;
283+
}
284+
const player_to_cm = (players_after + playerIndex) % game.players.length;
285+
const player_chop = common.chop(state.hands[player_to_cm]);
286+
// make sure the player has a chop
287+
if (player_chop === undefined) {
288+
resolve_discard(game, action, DISCARD_INTERP.NONE);
289+
return game;
290+
}
291+
// chop move
292+
console.log(player_to_cm);
293+
perform_cm(state, common, [player_chop]);
294+
}
295+
}
273296
if (game.level >= LEVEL.LAST_RESORTS && !action.failed && !state.inEndgame()) {
274297
let interp = check_sdcm(game, action, before_trash, old_chop);
275298

@@ -344,28 +367,7 @@ export function interpret_discard(game, action) {
344367
return game;
345368
}
346369
}
347-
// Check if a Trash Order Chop Move happened.
348-
if (game.level >= LEVEL.TRASH_PUSH && !state.inEndgame()) {
349-
const leftmost_kt = before_trash.sort((a, b) => b - a)[0];
350-
if (order !== leftmost_kt) {
351-
const players_after = before_trash.indexOf(order);
352-
// make sure the discarded card is actually known trash
353-
if (players_after === -1 || players_after >= game.players.length) {
354-
resolve_discard(game, action, DISCARD_INTERP.NONE);
355-
return game;
356-
}
357-
const player_to_cm = (players_after + playerIndex) % game.players.length;
358-
const player_chop = common.chop(state.hands[player_to_cm]);
359-
// make sure the player has a chop
360-
if (player_chop === undefined) {
361-
resolve_discard(game, action, DISCARD_INTERP.NONE);
362-
return game;
363-
}
364-
// chop move
365-
console.log(player_to_cm);
366-
perform_cm(state, common, [player_chop]);
367-
}
368-
}
370+
369371
resolve_discard(game, action, DISCARD_INTERP.NONE);
370372
return game;
371373
}

test/h-group/level-14.js

+19
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,23 @@ describe('trash order chop move', () => {
218218
const action = await game.take_action();
219219
ExAsserts.objHasProperties(action, { type: ACTION.DISCARD, target: game.state.hands[PLAYER.ALICE][2] }, `Expected (Discard slot 3) but got ${logPerformAction(action)}`);
220220
});
221+
222+
it('recognizes a Shout TOCM', async () => {
223+
const game = setup(HGroup, [
224+
['xx', 'xx', 'xx', 'xx', 'xx'],
225+
['y1', 'p3', 'g4', 'p4', 'r1'],
226+
['r1', 'y1', 'g1', 'p2', 'b5']
227+
], {
228+
level: { min: 14 },
229+
play_stacks: [2, 2, 5, 0, 4],
230+
starting: PLAYER.BOB
231+
});
232+
takeTurn(game, 'Bob clues green to Alice (slots 2,3)');
233+
takeTurn(game, 'Cathy clues blue to Alice (slot 1)');
234+
takeTurn(game, 'Alice discards g2 (slot 3)', 'r5');
235+
236+
// Cathy should chop move.
237+
const action = await game.take_action();
238+
assert.ok(game.common.thoughts[game.state.hands[PLAYER.CATHY][4]].chop_moved);
239+
});
221240
});

0 commit comments

Comments
 (0)