Fix legal moves calculation when bearing off after making a move
This commit is contained in:
parent
823d059151
commit
fa229d8ae6
4 changed files with 8 additions and 7 deletions
3
game.go
3
game.go
|
@ -570,13 +570,14 @@ func (g *Game) LegalMoves(local bool) [][]int8 {
|
|||
}
|
||||
onBar := g.Board[barSpace] != 0
|
||||
available, _ := b.Available(g.Turn)
|
||||
mayBearOff := b.MayBearOff(g.Turn)
|
||||
var moves [][]int8
|
||||
for i := range available {
|
||||
for j := range available[i] {
|
||||
if available[i][j][0] == 0 && available[i][j][1] == 0 {
|
||||
break
|
||||
}
|
||||
if (!onBar || (onBar && available[i][j][0] == barSpace)) && PlayerCheckers(g.Board[available[i][j][0]], g.Turn) != 0 {
|
||||
if (!onBar || (onBar && available[i][j][0] == barSpace)) && ((available[i][j][1] != tabula.SpaceHomePlayer && available[i][j][1] != tabula.SpaceHomeOpponent) || mayBearOff) && PlayerCheckers(g.Board[available[i][j][0]], g.Turn) != 0 {
|
||||
var found bool
|
||||
for _, m := range moves {
|
||||
if m[0] == available[i][j][0] && m[1] == available[i][j][1] {
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module code.rocket9labs.com/tslocum/bgammon
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240702103603-bf434f63caac
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240703054156-ce0b448f0999
|
||||
github.com/alexedwards/argon2id v1.0.0
|
||||
github.com/gobwas/ws v1.4.0
|
||||
github.com/gorilla/mux v1.8.1
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,7 +1,7 @@
|
|||
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b h1:Y0a14Kf/hSYepSmp4ZfDeE4CZZGBGBS97CNjCbKJm0c=
|
||||
code.rocket9labs.com/tslocum/bei v0.0.0-20240108012722-6db380cc190b/go.mod h1:tS60/VNAJphKvDBkSLQhKALa15msIAuWWfEKNc4oFZc=
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240702103603-bf434f63caac h1:czLpkEDTDz0t3avx2ppkWJvKtnQclepPjuOX4rrVHI4=
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240702103603-bf434f63caac/go.mod h1:WEJXESKXqrMFLAArikQ79lpRibNeeE1C0VruxXYMF5M=
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240703054156-ce0b448f0999 h1:PwfoDBtxVT3TwL2KpoijPKi6NQsGu6cXhPVoQeqKJWM=
|
||||
code.rocket9labs.com/tslocum/tabula v0.0.0-20240703054156-ce0b448f0999/go.mod h1:WEJXESKXqrMFLAArikQ79lpRibNeeE1C0VruxXYMF5M=
|
||||
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
|
||||
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
||||
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
||||
|
|
|
@ -1251,13 +1251,13 @@ COMMANDS:
|
|||
}
|
||||
|
||||
clientGame.Turn = 2
|
||||
clientGame.Roll1 = 5
|
||||
clientGame.Roll2 = 5
|
||||
clientGame.Roll1 = 4
|
||||
clientGame.Roll2 = 6
|
||||
clientGame.Roll3 = 0
|
||||
clientGame.Variant = 0
|
||||
clientGame.Player1.Entered = true
|
||||
clientGame.Player2.Entered = true
|
||||
clientGame.Board = []int8{1, 1, 2, 2, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -4, -3, -2, -2, -2, -1, 0, 0, 0}
|
||||
clientGame.Board = []int8{0, 0, 2, 2, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 1, -3, 1, 0, -3, -6, -2, 0, 0, 0}
|
||||
|
||||
log.Println(clientGame.Board[0:28])
|
||||
|
||||
|
|
Loading…
Reference in a new issue