diff --git a/cmd/bgammon-server/server.go b/cmd/bgammon-server/server.go index e59a0b4..cdd7a94 100644 --- a/cmd/bgammon-server/server.go +++ b/cmd/bgammon-server/server.go @@ -372,8 +372,10 @@ COMMANDS: rejoin = g.rejoin2 } if rejoin { - g.addClient(cmd.client) - cmd.client.sendNotice(fmt.Sprintf("Rejoined match: %s", g.name)) + ok, _ := g.addClient(cmd.client) + if ok { + cmd.client.sendNotice(fmt.Sprintf("Rejoined match: %s", g.name)) + } } } s.gamesLock.RUnlock() @@ -567,15 +569,16 @@ COMMANDS: s.gamesLock.Unlock() continue COMMANDS } - ok, reason := g.addClient(cmd.client) + s.gamesLock.Unlock() + if !ok { cmd.client.sendEvent(&bgammon.EventFailedJoin{ Reason: reason, }) + } else { + cmd.client.sendNotice(fmt.Sprintf("Joined match: %s", g.name)) } - s.gamesLock.Unlock() - cmd.client.sendNotice(fmt.Sprintf("Joined match: %s", g.name)) continue COMMANDS } } diff --git a/game.go b/game.go index 0c87e01..e0b3008 100644 --- a/game.go +++ b/game.go @@ -137,6 +137,12 @@ func (g *Game) addMove(move []int) bool { return true } +// AddLocalMove adds a move without performing any validation. This is useful when +// adding a move locally while waiting for an EventBoard response from the server. +func (g *Game) AddLocalMove(move []int) bool { + return g.addMove(move) +} + func (g *Game) ExpandMove(move []int, currentSpace int, moves [][]int) ([][]int, bool) { l := g.LegalMoves() var hitMoves [][]int @@ -301,7 +307,6 @@ func (g *Game) LegalMoves() [][]int { } haveDiceRoll := func(from, to int) int { - // TODO diff needs to account for bar and home special spaces diff := SpaceDiff(from, to) var c int for _, roll := range rolls { @@ -412,11 +417,11 @@ func (g *Game) LegalMoves() [][]int { } // Move normally. - lastSpace := 1 dir := -1 + lastSpace := 1 if g.Turn == 2 { - lastSpace = 24 dir = 1 + lastSpace = 24 } g.iterateSpaces(space+dir, lastSpace, func(to int, spaceCount int) {