Fix checking whether players must enter from the bar

This commit is contained in:
Trevor Slocum 2023-09-18 18:15:20 -07:00
parent e6b46bf42c
commit 92a8adec01

11
game.go
View file

@ -348,12 +348,15 @@ func (g *Game) LegalMoves() [][]int {
var moves [][]int
barSpace := SpaceBarPlayer
if g.Turn == 2 {
var mustEnter bool
var barSpace int
if PlayerCheckers(g.Board[SpaceBarPlayer], g.Turn) > 0 {
mustEnter = true
barSpace = SpaceBarPlayer
} else if PlayerCheckers(g.Board[SpaceBarOpponent], g.Turn) > 0 {
mustEnter = true
barSpace = SpaceBarOpponent
}
mustEnter := g.Board[barSpace] != 0
if mustEnter { // Must enter from bar.
from, to := HomeRange(g.opponentPlayer().Number)
g.iterateSpaces(from, to, func(homeSpace int, spaceCount int) {