Problem
The gammon/backgammon detection feature (detectGameOutcome() in src/Game/index.ts) was added in commit af64165 with 7 tests, but those tests only validate:
- The
GAME_OUTCOME_POINTS constant values
- Type structure of
BackgammonGameCompleted
- Score arithmetic (
basePoints * cubeValue)
No test actually exercises detectGameOutcome() against a real board with checkers placed in gammon/backgammon positions. The function's board-inspection logic (checking board.off, board.bar, and winner's home board) is untested.
Implementation Plan
1. Create board fixture helpers
Build helpers that construct a BackgammonBoard with checkers in specific positions:
createNormalWinBoard() — opponent has ≥1 checker in board.off
createGammonBoard() — opponent has 0 in board.off, no checkers in winner's home or on bar
createBackgammonBarBoard() — opponent has 0 in board.off, checker(s) on board.bar
createBackgammonHomeBoard() — opponent has 0 in board.off, checker(s) in winner's home board (positions 1-6 from winner's perspective)
2. Write integration tests
Test detectGameOutcome() directly (may need to export it or test via Game.move() triggering a win):
| Test Case |
Board Setup |
Expected Outcome |
| Normal win |
Opponent has 3 checkers borne off |
'normal' (1pt) |
| Gammon |
Opponent has 0 off, all in their own home |
'gammon' (2pt) |
| Backgammon (bar) |
Opponent has 0 off, 2 on bar |
'backgammon' (3pt) |
| Backgammon (winner's home) |
Opponent has 0 off, 1 in winner's home board |
'backgammon' (3pt) |
| Backgammon (both) |
Opponent has 0 off, 1 on bar + 1 in winner's home |
'backgammon' (3pt) |
| Gammon with cube |
Gammon with cube at 4 |
finalScore === 8 |
| Backgammon with cube |
Backgammon with cube at 2 |
finalScore === 6 |
3. Test direction independence
Run each scenario for both clockwise and counterclockwise winners to verify the position[direction] lookup works correctly for both players.
4. Edge case: Jacoby rule interaction
Verify that a gammon/backgammon is downgraded to normal when Jacoby rule is active and cube was never turned.
Files to modify
src/Game/__tests__/game-outcome-detection.test.ts — expand existing test file
src/Game/index.ts — may need to export detectGameOutcome for direct testing (or test through Game.move() win path)
Problem
The gammon/backgammon detection feature (
detectGameOutcome()insrc/Game/index.ts) was added in commitaf64165with 7 tests, but those tests only validate:GAME_OUTCOME_POINTSconstant valuesBackgammonGameCompletedbasePoints * cubeValue)No test actually exercises
detectGameOutcome()against a real board with checkers placed in gammon/backgammon positions. The function's board-inspection logic (checkingboard.off,board.bar, and winner's home board) is untested.Implementation Plan
1. Create board fixture helpers
Build helpers that construct a
BackgammonBoardwith checkers in specific positions:createNormalWinBoard()— opponent has ≥1 checker inboard.offcreateGammonBoard()— opponent has 0 inboard.off, no checkers in winner's home or on barcreateBackgammonBarBoard()— opponent has 0 inboard.off, checker(s) onboard.barcreateBackgammonHomeBoard()— opponent has 0 inboard.off, checker(s) in winner's home board (positions 1-6 from winner's perspective)2. Write integration tests
Test
detectGameOutcome()directly (may need to export it or test viaGame.move()triggering a win):'normal'(1pt)'gammon'(2pt)'backgammon'(3pt)'backgammon'(3pt)'backgammon'(3pt)finalScore === 8finalScore === 63. Test direction independence
Run each scenario for both clockwise and counterclockwise winners to verify the
position[direction]lookup works correctly for both players.4. Edge case: Jacoby rule interaction
Verify that a gammon/backgammon is downgraded to normal when Jacoby rule is active and cube was never turned.
Files to modify
src/Game/__tests__/game-outcome-detection.test.ts— expand existing test filesrc/Game/index.ts— may need to exportdetectGameOutcomefor direct testing (or test throughGame.move()win path)