Documentation
¶
Overview ¶
package Game implements the core logic of rock paper scissors lizard spock
Index ¶
Constants ¶
const ( NUM_PLAYERS = 2 GAMEID_LENGTH = 5 )
Variables ¶
This section is empty.
Functions ¶
func Beats ¶
Beats returns if first would beat second also returns the verb needed <first> crushes <second> In the case of a tie, returns "ties" as the verb
func GenerateRandomBytes ¶
GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func GenerateRandomString ¶
GenerateRandomString returns a random string of length N
Types ¶
type Game ¶
type Game struct { // ID is the identifier of the overall game ID string // Round tracks which round of the game is currently active Round int // PlayCount keeps track of how many plays have been submitted PlayCount int // Players is indexed by Player.ID and points to player records Players map[string]*Player // RoundSummary is a summary of the previous round ("Rock beats Scissors") RoundSummary string // Winner is the Player.ID which won the last round. Winner string }
Game is the key data for the overall game
func (*Game) AdvanceGame ¶
AdvanceGame updates a game to resolve the winner, round, etc
type GameContext ¶
type GameContext struct { Game *Game // ID of the current player inside the game ActingPlayer *Player }
GameContext is a container for the overall game and the current player action in it
func NewGameContext ¶
func NewGameContext(playerID, playerAddress string, game *Game) (*GameContext, error)
func (*GameContext) AssignPlayer ¶
func (gc *GameContext) AssignPlayer(p *Player) error
AssignPlayer sets a player to be P1 or P2
func (*GameContext) Play ¶
func (gc *GameContext) Play(play string) error
type Player ¶
type Player struct { // ID is the user-supplied user identifier ID string // Address is the connection id (or other location) for how to get to the player // It may change over time for the same player, e.g. if they reconnect Address string // Play is the player's last move Play string // Round is the last round played by the player Round int // Score is the player's score Score int // Game is the GameID this player is associated with Game string // WonLastRound identifies if the player ... won the last round WonLastRound bool }
Player stores relevant information about a current player's state