Retain dice rolls

This commit is contained in:
Trevor Slocum 2021-09-12 17:18:54 -07:00
parent 63ce61f2bf
commit 9b048ec05d
2 changed files with 34 additions and 4 deletions

View File

@ -217,17 +217,35 @@ func (b *Board) SetState(state string) {
}*/
s := strings.Split(state, ":")
newPlayers := s[StatePlayerName] != b.s[StatePlayerName] || s[StateOpponentName] != b.s[StateOpponentName]
copy(b.s, s)
var err error
v := make([]int, 50)
var err error
for i := 0; i < 50; i++ {
v[i], err = strconv.Atoi(b.s[i+2])
if err != nil {
log.Fatal(err)
}
}
newTurn := v[StateTurn] != b.v[StateTurn]
// Retain dice rolls
if !newPlayers && !newTurn {
copyDice := []int{
StatePlayerDice1,
StatePlayerDice2,
StateOpponentDice1,
StateOpponentDice2,
}
for _, vi := range copyDice {
if v[vi] == 0 {
v[vi] = b.v[vi]
}
}
}
copy(b.v, v)
/*if b.v[StateTurn] != lastTurn {
@ -434,8 +452,10 @@ func (b *Board) allPlayerPiecesInHomeBoard() bool {
if index < 0 || index > 25 {
return false
}
return (b.v[StatePlayerColor] == 1 && b.v[StateBoardSpace0+index] > 0) ||
(b.v[StatePlayerColor] == -1 && b.v[StateBoardSpace0+index] < 0)
value := b.v[StateBoardSpace0+index]
mod := b.v[StatePlayerColor]
value -= b.client.Board.Premovefrom[index] * mod
return value != 0
}
for i := 1; i < 24; i++ {
if i >= homeBoardStart && i <= homeBoardEnd {

View File

@ -682,6 +682,16 @@ func (c *Client) eventLoop() {
}
c.Board.SimplifyMoves()
c.Board.v[StateTurn] = player * -1
if c.Board.v[StateTurn] == c.Board.v[StatePlayerColor] {
c.Board.v[StatePlayerDice1] = 0
c.Board.v[StatePlayerDice2] = 0
} else {
c.Board.v[StateOpponentDice1] = 0
c.Board.v[StateOpponentDice2] = 0
}
c.Board.Draw()
bs := string(b)