Skip to content

Commit 436cfec

Browse files
committed
allow player to discard trash that isn't leftmost
1 parent 9856d55 commit 436cfec

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/conventions/h-group/take-action.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ export function find_all_discards(game, playerIndex) {
164164
logger.off();
165165
const positional = find_positional_discard(game, playerIndex, discardable ?? -1);
166166
logger.on();
167-
168-
return positional !== undefined ? [positional] : (discardable ? [{ misplay: false, order: discardable }] : []);
167+
// this code is here to support TOCMs
168+
const all_discards = [{ misplay: false, order: discardable }];
169+
for (const c of trash_cards) {
170+
if (c != discardable) {
171+
all_discards.push({misplay: false, order: c});
172+
}
173+
}
174+
return positional !== undefined ? [positional] : (discardable ? all_discards : []);
169175
}
170176

171177
/**

test/h-group/level-14.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,21 @@ describe('trash order chop move', () => {
183183
assert.ok(!game.common.thoughts[game.state.hands[PLAYER.CATHY][4]].chop_moved);
184184
});
185185

186-
it('performs a TOCM if the card can\'t be saved otherwise', async () => {
186+
it('performs a TOCM for good cards if it can\'t otherwise cm', async () => {
187187
const game = setup(HGroup, [
188188
['xx', 'xx', 'xx', 'xx', 'xx'],
189-
['r3', 'b3', 'y1', 'g1', 'g3'],
190-
['g4', 'r4', 'y4', 'g4', 'u5']
189+
['r5', 'p3', 'g4', 'p4', 'y4'],
190+
['r1', 'y1', 'g1', 'p2', 'g2']
191191
], {
192192
level: { min: 14 },
193-
play_stacks: [1, 1, 1, 1, 1],
194-
starting: PLAYER.ALICE,
195-
variant: VARIANTS.NULL
193+
play_stacks: [2, 2, 4, 1, 4],
194+
starting: PLAYER.CATHY
196195
});
197196

198-
takeTurn(game, 'Alice clues 1 to Bob (slots 3,4)');
197+
takeTurn(game, 'Cathy clues 1 to Alice (slots 3,4)');
199198

200-
// Bob should discard slot 4 to chop move null 5.
199+
// Alice should discard slot 4 to chop move yellow 3.
201200
const action = await game.take_action();
202-
ExAsserts.objHasProperties(action, { type: ACTION.DISCARD, target: game.state.hands[PLAYER.BOB][3] }, `Expected (Discard slot 4) but got ${logPerformAction(action)}`);
201+
ExAsserts.objHasProperties(action, { type: ACTION.DISCARD, target: game.state.hands[PLAYER.ALICE][3] }, `Expected (Discard slot 4) but got ${logPerformAction(action)}`);
203202
});
204203
});

0 commit comments

Comments
 (0)