impl all bool phases
This commit is contained in:
@@ -61,20 +61,38 @@ func trade(game *entity.Game, max interface{}) bool {
|
|||||||
if game == nil {
|
if game == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
panic("not impl")
|
|
||||||
|
n := convertNumber(max)
|
||||||
|
|
||||||
|
for _, player := range game.ActivePlayers() {
|
||||||
|
if player.Checked {
|
||||||
|
for len(player.Hand.Public) < n {
|
||||||
|
card := game.Deck.Draw()
|
||||||
|
player.Hand.Push(card)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete := game.IsAllActivePlayersChecked()
|
||||||
|
if complete {
|
||||||
|
game.NextPhase()
|
||||||
|
game.NextTurn()
|
||||||
|
}
|
||||||
|
return complete
|
||||||
}
|
}
|
||||||
|
|
||||||
func end(game *entity.Game, _ interface{}) bool {
|
func end(game *entity.Game, _ interface{}) bool {
|
||||||
if game == nil {
|
if game == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
panic("not impl")
|
game.NextPhase()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func playerCount(game *entity.Game, v interface{}) bool {
|
func playerCount(game *entity.Game, v interface{}) bool {
|
||||||
if game == nil {
|
if game == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
v2 := convertNumber(charge)
|
n := convertNumber(v)
|
||||||
return len(game.ActivePlayers()) == v2
|
return len(game.ActivePlayers()) == n
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -363,3 +363,268 @@ func TestBet(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTrade(t *testing.T) {
|
||||||
|
cases := map[string]struct {
|
||||||
|
game *entity.Game
|
||||||
|
check func(*testing.T, bool, *entity.Game)
|
||||||
|
}{
|
||||||
|
"game is nil": {
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"players is nil": {
|
||||||
|
game: &entity.Game{},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if !a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"1 player no trades checked": {
|
||||||
|
game: &entity.Game{
|
||||||
|
Players: []entity.Player{
|
||||||
|
entity.Player{
|
||||||
|
Active: true,
|
||||||
|
Checked: true,
|
||||||
|
Hand: entity.Hand{
|
||||||
|
Public: []entity.Card{
|
||||||
|
entity.Card{Suit: 4},
|
||||||
|
entity.Card{Suit: 4},
|
||||||
|
entity.Card{Suit: 4},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if !a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
if !(game.Players[0].Hand.Public[0].Suit == 4 && game.Players[0].Hand.Public[1].Suit == 4 && game.Players[0].Hand.Public[2].Suit == 4) {
|
||||||
|
t.Fatal(game.Players[0].Hand.Public)
|
||||||
|
}
|
||||||
|
if game.Players[0].Checked {
|
||||||
|
t.Fatal(game.Players[0].Checked)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"1 player trades checked": {
|
||||||
|
game: &entity.Game{
|
||||||
|
Players: []entity.Player{
|
||||||
|
entity.Player{
|
||||||
|
Active: true,
|
||||||
|
Checked: true,
|
||||||
|
Hand: entity.Hand{
|
||||||
|
Public: []entity.Card{
|
||||||
|
entity.Card{Suit: 4},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if !a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
if !(game.Players[0].Hand.Public[0].Suit == 4) {
|
||||||
|
t.Fatal(game.Players[0].Hand.Public[0])
|
||||||
|
}
|
||||||
|
if len(game.Players[0].Hand.Public) != 3 {
|
||||||
|
t.Fatal(len(game.Players[0].Hand.Public))
|
||||||
|
}
|
||||||
|
if game.Players[0].Checked {
|
||||||
|
t.Fatal(game.Players[0].Checked)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"1 player no trades not checked": {
|
||||||
|
game: &entity.Game{
|
||||||
|
Players: []entity.Player{
|
||||||
|
entity.Player{
|
||||||
|
Active: true,
|
||||||
|
Checked: false,
|
||||||
|
Hand: entity.Hand{
|
||||||
|
Public: []entity.Card{
|
||||||
|
entity.Card{Suit: 4},
|
||||||
|
entity.Card{Suit: 4},
|
||||||
|
entity.Card{Suit: 4},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
if !(game.Players[0].Hand.Public[0].Suit == 4 && game.Players[0].Hand.Public[1].Suit == 4 && game.Players[0].Hand.Public[2].Suit == 4) {
|
||||||
|
t.Fatal(game.Players[0].Hand.Public)
|
||||||
|
}
|
||||||
|
if game.Players[0].Checked {
|
||||||
|
t.Fatal(game.Players[0].Checked)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"1 player trades not checked": {
|
||||||
|
game: &entity.Game{
|
||||||
|
Players: []entity.Player{
|
||||||
|
entity.Player{
|
||||||
|
Active: true,
|
||||||
|
Checked: false,
|
||||||
|
Hand: entity.Hand{
|
||||||
|
Public: []entity.Card{
|
||||||
|
entity.Card{Suit: 4},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
if game.Players[0].Hand.Public[0].Suit != 4 {
|
||||||
|
t.Fatal(game.Players[0].Hand.Public[0])
|
||||||
|
}
|
||||||
|
if len(game.Players[0].Hand.Public) != 1 {
|
||||||
|
t.Fatal(len(game.Players[0].Hand.Public))
|
||||||
|
}
|
||||||
|
if game.Players[0].Checked {
|
||||||
|
t.Fatal(game.Players[0].Checked)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"1 player trades not checked, 1 player trades checked": {
|
||||||
|
game: &entity.Game{
|
||||||
|
Players: []entity.Player{
|
||||||
|
entity.Player{
|
||||||
|
Active: true,
|
||||||
|
Checked: false,
|
||||||
|
Hand: entity.Hand{
|
||||||
|
Public: []entity.Card{
|
||||||
|
entity.Card{Suit: 4},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
entity.Player{
|
||||||
|
Active: true,
|
||||||
|
Checked: true,
|
||||||
|
Hand: entity.Hand{
|
||||||
|
Public: []entity.Card{
|
||||||
|
entity.Card{Suit: 3},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
if game.Players[0].Hand.Public[0].Suit != 4 {
|
||||||
|
t.Fatal(game.Players[0].Hand.Public[0])
|
||||||
|
}
|
||||||
|
if len(game.Players[0].Hand.Public) != 1 {
|
||||||
|
t.Fatal(len(game.Players[0].Hand.Public))
|
||||||
|
}
|
||||||
|
if game.Players[0].Checked {
|
||||||
|
t.Fatal(game.Players[0].Checked)
|
||||||
|
}
|
||||||
|
if game.Players[1].Hand.Public[0].Suit != 3 {
|
||||||
|
t.Fatal(game.Players[1].Hand.Public[0])
|
||||||
|
}
|
||||||
|
if len(game.Players[1].Hand.Public) != 3 {
|
||||||
|
t.Fatal(len(game.Players[1].Hand.Public))
|
||||||
|
}
|
||||||
|
if !game.Players[1].Checked {
|
||||||
|
t.Fatal(game.Players[1].Checked)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, d := range cases {
|
||||||
|
c := d
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
if c.game != nil {
|
||||||
|
c.game.Deck = newDeck()
|
||||||
|
}
|
||||||
|
got := trade(c.game, 3)
|
||||||
|
c.check(t, got, c.game)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPlayerCount(t *testing.T) {
|
||||||
|
cases := map[string]struct {
|
||||||
|
game *entity.Game
|
||||||
|
check func(*testing.T, bool, *entity.Game)
|
||||||
|
}{
|
||||||
|
"game is nil": {
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"players is nil": {
|
||||||
|
game: &entity.Game{},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"players is short": {
|
||||||
|
game: &entity.Game{
|
||||||
|
Players: []entity.Player{
|
||||||
|
entity.Player{Active: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"players is high": {
|
||||||
|
game: &entity.Game{
|
||||||
|
Players: []entity.Player{
|
||||||
|
entity.Player{Active: true},
|
||||||
|
entity.Player{Active: true},
|
||||||
|
entity.Player{Active: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"players is right": {
|
||||||
|
game: &entity.Game{
|
||||||
|
Players: []entity.Player{
|
||||||
|
entity.Player{Active: true},
|
||||||
|
entity.Player{Active: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: func(t *testing.T, a bool, game *entity.Game) {
|
||||||
|
if !a {
|
||||||
|
t.Fatal(a)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, d := range cases {
|
||||||
|
c := d
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
got := playerCount(c.game, 2)
|
||||||
|
c.check(t, got, c.game)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user