Skip to content

Commit

Permalink
game: reset players in Reset method
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Mar 28, 2022
1 parent a14335a commit ca71ad6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ func (g *Game) Reset() {
}

*g.board = *board.Create(g.board.Width(), g.board.Height(), g.board.ChainLength())

var p1Cb, p2Cb func(letter.Letter) int

switch g.players.Player1().Type() {
case player.PlayerPC:
p1Cb = func(l letter.Letter) int { return pcplayer.GetPCMove(g.board, l) }
case player.PlayerPerson:
p1Cb = func(_ letter.Letter) int { return g.getUserAction() }
}

switch g.players.Player2().Type() {
case player.PlayerPC:
p2Cb = func(l letter.Letter) int { return pcplayer.GetPCMove(g.board, l) }
case player.PlayerPerson:
p2Cb = func(_ letter.Letter) int { return g.getUserAction() }
}

g.players = players.Create(g.players.Player1().Type(), p1Cb, g.players.Player2().Type(), p2Cb)
}

// Stop safely stops the game loop invoked by (*Game).Run.
Expand Down

0 comments on commit ca71ad6

Please sign in to comment.