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 <[email protected]> Claude-Session: https://claude.ai/code/session_01DCuRESmSZeJoJond43itw2
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user