From 6d490a50b1e3ca02746fa8d3619589712f846d4e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Aug 2026 19:13:18 +0000 Subject: [PATCH] Test that a cribbage partnership plays for its own crib Four-handed is the only table where the crib in front of somebody else is still yours, and the lay-away is where that has to be read. Two AI seats facing each other take more than half the games against two random ones, which a side giving away half its own cribs would not. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01DCuRESmSZeJoJond43itw2 --- .../games/game/cribbage/CribbageRulesTest.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/src/test/java/org/prolibertate/games/game/cribbage/CribbageRulesTest.kt b/app/src/test/java/org/prolibertate/games/game/cribbage/CribbageRulesTest.kt index 7ad541e..4d25950 100644 --- a/app/src/test/java/org/prolibertate/games/game/cribbage/CribbageRulesTest.kt +++ b/app/src/test/java/org/prolibertate/games/game/cribbage/CribbageRulesTest.kt @@ -447,6 +447,39 @@ class CribbageRulesTest { assertTrue("ai won $aiWins of ten against random play", aiWins > randomWins) } + @Test + fun `a partnership plays for its own crib and not just its own hand`() { + // Four-handed, with the two AI seats facing each other. The lay-away is + // where a partner's crib has to count as your own, so a side that + // treated it as an opponent's would be giving away half its own cribs. + val ai = CribbageAi() + var aiWins = 0 + + repeat(8) { iteration -> + val random = Random(900L + iteration) + val options = CribbageOptions(playerCount = 4, pointsToWin = 61) + var state = CribbageRules.initialState(config(options, seed = 500L + iteration)) + var guard = 0 + while (!CribbageRules.isFinished(state) && guard++ < 40000) { + val seat = CribbageRules.currentSeat(state) + if (seat == null) { + state = CribbageRules.nextHand(state) + continue + } + val legal = CribbageRules.legalMoves(state, seat) + val move = if (options.teamOf(seat) == 0) { + ai.chooseMove(state, seat, legal) + } else { + legal[random.nextInt(legal.size)] + } + state = CribbageRules.applyMove(state, seat, move) + } + if (state.winner == 0) aiWins++ + } + + assertTrue("the ai partnership won $aiWins of eight", aiWins > 4) + } + // -- Redaction and wire format ------------------------------------------ @Test