diff --git a/DESIGN.md b/DESIGN.md new file mode 100644 index 0000000..fc2836d --- /dev/null +++ b/DESIGN.md @@ -0,0 +1,33 @@ +# Design + +[tabula](https://code.rocket9labs.com/tslocum/tabula) is a multi-threaded backgammon analysis engine. +To find the best move, the engine performs a series of simulations and scores the resulting game states. +The result with the lowest score is the best move. + +## Scoring + +### Space value + +Space value is defined as what the term 'pips' would normally refer to. The +value of a space is the same as the space number as it would appear to the +player being scored. + +### Pseudopips + +All scoring calculations use pseudopips. + +A pseudopip value is assigned to each board space as follows: + +- Each space is worth 6 pseudopips plus **double the space value**. +- Spaces outside of the player's home board are worth an additional 6 pseudopips. + +Space 2 (from the perspective of the player being scored) is therefore worth 10 +pseudopips, space 6 is worth 18, space 7 is worth 26 and the bar space is worth 62. + +## Analysis + +### Step 1: Simulate all legal move available to the player + +### Step 2: Simulate all opponent dice rolls and opponent moves that may follow the above simulations + +### Step 3: Sort simulation results by score diff --git a/board.go b/board.go index 4f979c2..b7d7489 100644 --- a/board.go +++ b/board.go @@ -501,7 +501,9 @@ func opponent(player int) int { } func spaceValue(player int, space int) int { - if player == 1 { + if space == SpaceBarPlayer || space == SpaceBarOpponent { + return 25 + } else if player == 1 { return space } else { return 25 - space