Require checkers to enter from bar before moving other checkers

This commit is contained in:
Trevor Slocum 2024-01-11 18:42:34 -08:00
parent 84896b2982
commit 5410496772
2 changed files with 7 additions and 2 deletions

View file

@ -504,6 +504,11 @@ func (g *Game) LegalMoves(local bool) [][]int8 {
if !ok {
return nil
}
barSpace := SpaceBarPlayer
if g.Turn == 2 {
barSpace = SpaceBarOpponent
}
onBar := g.Board[barSpace] != 0
available, _ := b.Available(g.Turn)
var moves [][]int8
for i := range available {
@ -511,7 +516,7 @@ func (g *Game) LegalMoves(local bool) [][]int8 {
if available[i][j][0] == 0 && available[i][j][1] == 0 {
break
}
if PlayerCheckers(g.Board[available[i][j][0]], g.Turn) != 0 {
if (!onBar || (onBar && available[i][j][0] == barSpace)) && 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] {

View file

@ -345,7 +345,7 @@ func loginAccount(passwordSalt string, username []byte, password []byte) (*accou
a := &account{}
var autoplay, highlight, pips, moves, flip, advanced int
err = tx.QueryRow(context.Background(), "SELECT id, email, username, password, autoplay, highlight, pips, moves, flip, advanced FROM account WHERE username = $1 OR email = $2", bytes.ToLower(bytes.TrimSpace(username)), bytes.ToLower(bytes.TrimSpace(username))).Scan(&a.id, &a.email, &a.username, &a.password, &autoplay, &highlight, &pips, &moves, &flip, &advanced, &a.speed)
err = tx.QueryRow(context.Background(), "SELECT id, email, username, password, autoplay, highlight, pips, moves, flip, advanced, speed FROM account WHERE username = $1 OR email = $2", bytes.ToLower(bytes.TrimSpace(username)), bytes.ToLower(bytes.TrimSpace(username))).Scan(&a.id, &a.email, &a.username, &a.password, &autoplay, &highlight, &pips, &moves, &flip, &advanced, &a.speed)
if err != nil {
return nil, nil
} else if len(a.password) == 0 {