Create some subroutines and test
This commit is contained in:
80
src/game/rule/operation/phase.go
Normal file
80
src/game/rule/operation/phase.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package operation
|
||||
|
||||
import (
|
||||
"local/sandbox/cards/src/entity"
|
||||
)
|
||||
|
||||
func charge(game *entity.Game, charge interface{}) bool {
|
||||
if game == nil {
|
||||
return false
|
||||
}
|
||||
v := entity.Currency(convertNumber(charge))
|
||||
game.ChargeActivePlayers(v)
|
||||
game.NextPhase()
|
||||
return true
|
||||
}
|
||||
|
||||
func deal(game *entity.Game, deal interface{}) bool {
|
||||
if game == nil {
|
||||
return false
|
||||
}
|
||||
n := convertNumber(deal)
|
||||
game.Deal(n)
|
||||
game.NextPhase()
|
||||
return true
|
||||
}
|
||||
|
||||
func bet(game *entity.Game, _ interface{}) bool {
|
||||
if game == nil {
|
||||
return false
|
||||
}
|
||||
if len(game.ActivePlayers()) == 0 {
|
||||
game.NextPhase()
|
||||
game.NextTurn()
|
||||
return true
|
||||
}
|
||||
|
||||
player := &game.Players[game.Current.Turn]
|
||||
raised := player.Active && player.Bet > game.Current.Bet
|
||||
if raised {
|
||||
game.Current.Bet = player.Bet
|
||||
for i := range game.Players {
|
||||
game.Players[i].Checked = false
|
||||
}
|
||||
}
|
||||
player.Checked = player.Active && (player.Checked || player.Balance == 0 || player.Bet == game.Current.Bet)
|
||||
|
||||
if game.IsAllActivePlayersChecked() && game.IsPotRight() {
|
||||
game.NextPhase()
|
||||
game.NextTurn()
|
||||
return true
|
||||
}
|
||||
|
||||
if player.Checked {
|
||||
game.NextTurn()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func trade(game *entity.Game, max interface{}) bool {
|
||||
if game == nil {
|
||||
return false
|
||||
}
|
||||
panic("not impl")
|
||||
}
|
||||
|
||||
func end(game *entity.Game, _ interface{}) bool {
|
||||
if game == nil {
|
||||
return false
|
||||
}
|
||||
panic("not impl")
|
||||
}
|
||||
|
||||
func playerCount(game *entity.Game, v interface{}) bool {
|
||||
if game == nil {
|
||||
return false
|
||||
}
|
||||
v2 := convertNumber(charge)
|
||||
return len(game.ActivePlayers()) == v2
|
||||
}
|
||||
Reference in New Issue
Block a user