Skip to content

Commit ae8b20a

Browse files
committed
make the bot allowed to perform TOCMs
1 parent 436cfec commit ae8b20a

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

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

+31-2
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,23 @@ export async function take_action(game) {
609609
}
610610

611611
// Discard known trash at high pace, low clues
612-
if (best_playable_order === undefined && trash_orders.length > 0 && state.pace > state.numPlayers * 2 && state.clue_tokens <= 2)
612+
if (best_playable_order === undefined && trash_orders.length > 0 && state.pace > state.numPlayers * 2 && state.clue_tokens <= 2) {
613+
// check if a TOCM would be better than not doing a TOCM, starting from Bob
614+
let player_check_index = state.nextPlayerIndex(state.ourPlayerIndex);
615+
if (trash_orders.length >= 2 && game.level >= LEVEL.TRASH_PUSH) {
616+
for (let i = 1; i < trash_orders.length; i++) {
617+
const next_chop = me.chop(state.hands[player_check_index]);
618+
const chop_value = cardValue(state, me, state.deck[next_chop], next_chop);
619+
const new_chop_value = me.withThoughts(next_chop, (draft) => { draft.chop_moved = true; }).chopValue(state, nextPlayerIndex);
620+
if (new_chop_value < chop_value && chop_value >= 1) {
621+
return { tableID, type: ACTION.DISCARD, target: trash_orders[i] };
622+
}
623+
player_check_index = state.nextPlayerIndex(player_check_index);
624+
}
625+
}
626+
613627
return { tableID, type: ACTION.DISCARD, target: trash_orders[0] };
628+
}
614629

615630
// Shout Discard on a valuable card that moves chop to trash
616631
const next_chop = me.chop(state.hands[nextPlayerIndex]);
@@ -698,8 +713,22 @@ export async function take_action(game) {
698713
}
699714

700715
// Discard known trash (no pace requirement)
701-
if (trash_orders.length > 0 && !state.inEndgame() && state.clue_tokens < 8)
716+
if (trash_orders.length > 0 && !state.inEndgame() && state.clue_tokens < 8) {
717+
// check if a TOCM would be better than not doing a TOCM, starting from Bob
718+
let player_check_index = state.nextPlayerIndex(state.ourPlayerIndex);
719+
if (trash_orders.length >= 2 && game.level >= LEVEL.TRASH_PUSH) {
720+
for (let i = 1; i < trash_orders.length; i++) {
721+
const next_chop = me.chop(state.hands[player_check_index]);
722+
const chop_value = cardValue(state, me, state.deck[next_chop], next_chop);
723+
const new_chop_value = me.withThoughts(next_chop, (draft) => { draft.chop_moved = true; }).chopValue(state, nextPlayerIndex);
724+
if (new_chop_value < chop_value && chop_value >= 1) {
725+
return { tableID, type: ACTION.DISCARD, target: trash_orders[i] };
726+
}
727+
player_check_index = state.nextPlayerIndex(player_check_index);
728+
}
729+
}
702730
return { tableID, type: ACTION.DISCARD, target: trash_orders[0] };
731+
}
703732

704733
// Early save
705734
if (state.clue_tokens > 0 && urgent_actions[actionPrioritySize * 2].length > 0)

test/h-group/level-14.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ 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 for good cards if it can\'t otherwise cm', async () => {
186+
it('performs a TOCM for good cards', async () => {
187187
const game = setup(HGroup, [
188188
['xx', 'xx', 'xx', 'xx', 'xx'],
189189
['r5', 'p3', 'g4', 'p4', 'y4'],

0 commit comments

Comments
 (0)