Re-roll when starting an acey-deucey game
This commit is contained in:
parent
a87e493425
commit
b081b604e1
3 changed files with 44 additions and 3 deletions
|
@ -68,6 +68,7 @@ func (g *serverGame) roll(player int) bool {
|
|||
|
||||
g.Roll1 = randInt(6) + 1
|
||||
g.Roll2 = randInt(6) + 1
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -913,10 +913,40 @@ COMMANDS:
|
|||
})
|
||||
|
||||
if clientGame.Turn == 0 && clientGame.Roll1 != 0 && clientGame.Roll2 != 0 {
|
||||
reroll := func() {
|
||||
clientGame.eachClient(func(client *serverClient) {
|
||||
clientGame.sendBoard(client)
|
||||
})
|
||||
|
||||
clientGame.Roll1 = 0
|
||||
clientGame.Roll2 = 0
|
||||
if !clientGame.roll(clientGame.Turn) {
|
||||
log.Fatal("failed to re-roll while starting acey-deucey game")
|
||||
}
|
||||
|
||||
ev := &bgammon.EventRolled{
|
||||
Roll1: clientGame.Roll1,
|
||||
Roll2: clientGame.Roll2,
|
||||
}
|
||||
ev.Player = string(clientGame.Player1.Name)
|
||||
if clientGame.Turn == 2 {
|
||||
ev.Player = string(clientGame.Player2.Name)
|
||||
}
|
||||
clientGame.eachClient(func(client *serverClient) {
|
||||
client.sendEvent(ev)
|
||||
})
|
||||
}
|
||||
|
||||
if clientGame.Roll1 > clientGame.Roll2 {
|
||||
clientGame.Turn = 1
|
||||
if clientGame.Acey {
|
||||
reroll()
|
||||
}
|
||||
} else if clientGame.Roll2 > clientGame.Roll1 {
|
||||
clientGame.Turn = 2
|
||||
if clientGame.Acey {
|
||||
reroll()
|
||||
}
|
||||
} else {
|
||||
clientGame.Roll1 = 0
|
||||
clientGame.Roll2 = 0
|
||||
|
|
16
gamestate.go
16
gamestate.go
|
@ -61,8 +61,18 @@ func (g *GameState) SpaceAt(x int, y int) int {
|
|||
func (g *GameState) Pips(player int) int {
|
||||
var pips int
|
||||
var spaceValue int
|
||||
pips += PlayerCheckers(g.Board[SpaceBarPlayer], player) * 25
|
||||
pips += PlayerCheckers(g.Board[SpaceBarOpponent], player) * 25
|
||||
if player == 1 {
|
||||
pips += PlayerCheckers(g.Board[SpaceBarPlayer], player) * 25
|
||||
} else {
|
||||
pips += PlayerCheckers(g.Board[SpaceBarOpponent], player) * 25
|
||||
}
|
||||
if g.Acey {
|
||||
if player == 1 {
|
||||
pips += PlayerCheckers(g.Board[SpaceHomePlayer], player) * 25
|
||||
} else {
|
||||
pips += PlayerCheckers(g.Board[SpaceHomeOpponent], player) * 25
|
||||
}
|
||||
}
|
||||
for i := 1; i < 25; i++ {
|
||||
if player == g.PlayerNumber {
|
||||
spaceValue = i
|
||||
|
@ -76,7 +86,7 @@ func (g *GameState) Pips(player int) int {
|
|||
|
||||
// MayDouble returns whether the player may send the 'double' command.
|
||||
func (g *GameState) MayDouble() bool {
|
||||
if g.Spectating || g.Winner != 0 {
|
||||
if g.Spectating || g.Winner != 0 || g.Acey {
|
||||
return false
|
||||
}
|
||||
return g.Points != 1 && g.Turn != 0 && g.Turn == g.PlayerNumber && g.Roll1 == 0 && !g.DoubleOffered && (g.DoublePlayer == 0 || g.DoublePlayer == g.PlayerNumber)
|
||||
|
|
Loading…
Reference in a new issue