Documentation ¶
Overview ¶
Package game represents all the game play for liar's dice.
Index ¶
- Constants
- Variables
- type Balance
- type BalanceFmt
- type Banker
- type Bet
- type Cup
- type Game
- func (g *Game) AddAccount(ctx context.Context, player common.Address) error
- func (g *Game) ApplyOut(ctx context.Context, player common.Address, outs int) error
- func (g *Game) Bet(ctx context.Context, player common.Address, number int, suit int) error
- func (g *Game) CallLiar(ctx context.Context, player common.Address) (winningPlayer common.Address, losingPlayer common.Address, err error)
- func (g *Game) DateCreated() time.Time
- func (g *Game) ID() uuid.UUID
- func (g *Game) NextRound(ctx context.Context) (int, error)
- func (g *Game) NextTurn(ctx context.Context) error
- func (g *Game) QueryState(ctx context.Context) (State, error)
- func (g *Game) QueryStateByRound(ctx context.Context, round int) (State, error)
- func (g *Game) Reconcile(ctx context.Context) (*types.Transaction, *types.Receipt, error)
- func (g *Game) RollDice(ctx context.Context, player common.Address, manualRole ...int) error
- func (g *Game) StartGame(ctx context.Context) error
- func (g *Game) State() State
- func (g *Game) Status() string
- type State
- type Storer
Constants ¶
const ( StatusNewGame = "newgame" StatusPlaying = "playing" StatusRoundOver = "roundover" StatusGameOver = "gameover" StatusReconciled = "reconciled" )
Represents the different game status.
Variables ¶
var ErrNotFound = errors.New("game not found")
var Tables = newTables()
Tables maintains the set of games in the system.
Functions ¶
This section is empty.
Types ¶
type BalanceFmt ¶
BalanceFmt represents an individual formatted balance for a player.
type Banker ¶
type Banker interface { AccountBalance(ctx context.Context, player common.Address) (GWei *big.Float, err error) Reconcile(ctx context.Context, winningPlayer common.Address, losingPlayers []common.Address, anteGWei *big.Float, gameFeeGWei *big.Float) (*types.Transaction, *types.Receipt, error) }
Banker represents the ability to manage money for the game. Deposits and Withdrawls happen outside of game play.
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game represents a single game that is being played.
func New ¶
func New(ctx context.Context, log *logger.Logger, converter *currency.Converter, storer Storer, banker Banker, player common.Address, anteUSD float64) (*Game, error)
New creates a new game.
func (*Game) AddAccount ¶
AddAccount adds a player to the game. If the account already exists, the function will return an error.
func (*Game) ApplyOut ¶
ApplyOut will apply the specified number of outs to the account. If an account is out, it will check the number of active accounts, and end the round if there is only 1 left.
func (*Game) Bet ¶
Bet accepts a bet from an account, but validates the bet is valid first. If the bet is valid, it's added to the list of bets for the game. Then the next player is determined and set.
func (*Game) CallLiar ¶
func (g *Game) CallLiar(ctx context.Context, player common.Address) (winningPlayer common.Address, losingPlayer common.Address, err error)
CallLiar checks the last bet that was made and determines the winner and loser of the current round.
func (*Game) DateCreated ¶
DateCreated returns the date/time the game was created.
func (*Game) NextRound ¶
NextRound updates the game state for players who are out and determining which player goes next. The function returns the number of players left in the game.
func (*Game) QueryState ¶
QueryState retrieves the state for the current round of this game.
func (*Game) QueryStateByRound ¶
QueryStateByRound retrieves the state for the specified round of this game.
func (*Game) RollDice ¶
RollDice will generate 5 new random integers for the players cup. The caller can specific the dice if they choose.
type State ¶
type State struct { GameID uuid.UUID GameName string DateCreated time.Time Round int Status string PlayerLastOut common.Address PlayerLastWin common.Address PlayerTurn common.Address ExistingPlayers []common.Address Cups map[common.Address]Cup Bets []Bet Balances []BalanceFmt }
State represents a copy of the game state.
type Storer ¶
type Storer interface { Create(ctx context.Context, g *Game) error InsertRound(ctx context.Context, state State) error QueryStateByID(ctx context.Context, gameID uuid.UUID, round int) (State, error) }
Storer interface declares the behaviour this package needs to persist and retrieve data.