diff --git a/game/game.go b/game/game.go index 6461719..fa83ade 100644 --- a/game/game.go +++ b/game/game.go @@ -153,9 +153,9 @@ func (g *Match) Empty() bool { return len(g.shells) == 0 } -// Winner returns the player who won the current round, or nil if the round is -// not over. -func (g *Match) Winner() *Player { +// RoundWinner returns the player who won the current round, or nil if the +// round is not over. +func (g *Match) RoundWinner() *Player { if g.players[0].hp <= 0 { return &g.players[1] } @@ -165,6 +165,15 @@ func (g *Match) Winner() *Player { return nil } +// MatchWinner returns the player who has won the match, or nil if the match +// is not over. +func (g *Match) MatchWinner() *Player { + if g.round < 3 { + return nil + } + return g.RoundWinner() +} + // Shoot fires the shotgun, at the opponent if self is false and at the current // player if self is true. Afterward, the round or game may be over. // Returns ErrWrongTurn if id does not correspond to the current player. diff --git a/game/game_test.go b/game/game_test.go index b361c16..e7e7623 100644 --- a/game/game_test.go +++ b/game/game_test.go @@ -310,7 +310,7 @@ func TestGameWinner(t *testing.T) { g := New(dealer, chall) g.players[0].hp = c.p0 g.players[1].hp = c.p1 - if got := g.Winner(); deref(got).id != c.want { + if got := g.RoundWinner(); deref(got).id != c.want { t.Errorf("wrong winner: %#v doesn't have id %#v", got, c.want) } }) @@ -434,7 +434,7 @@ func TestConcede(t *testing.T) { t.Parallel() g := New(dealer, chall) g.Concede(c.p) - if got := g.Winner(); deref(got).id != c.winner { + if got := g.RoundWinner(); deref(got).id != c.winner { t.Errorf("wrong winner: %#v doesn't have id %#v", got, c.winner) } })