Fix bearing off

This commit is contained in:
Trevor Slocum 2024-11-16 22:40:06 -08:00
parent ff05d4a1dd
commit 1945642193

View file

@ -148,8 +148,21 @@ func parseMoves(g *bgammon.Game, moves []byte) ([4][2]int8, error) {
return [4][2]int8{}, fmt.Errorf("failed to parse gnubg moves: invalid to (%s): %s", move[:slash], moves)
}
if to == bgammon.SpaceHomePlayer && bgammon.PlayerCheckers(Game.Game.Board[from], 1) == 0 {
for space := from; space > 1; space-- {
if bgammon.PlayerCheckers(Game.Game.Board[space], 1) != 0 {
from = space
break
}
}
}
for j := 0; j < count; j++ {
m[mc][0], m[mc][1] = int8(from), int8(to)
ok, _ := Game.AddMoves([][]int8{{int8(from), int8(to)}}, true)
if !ok {
return [4][2]int8{}, fmt.Errorf("failed to add local moves (%d/%d): %s", from, to, moves)
}
mc++
}