Documentation
¶
Overview ¶
Package game encapsulates the main mechanics for a Crossword Game. It interacts heavily with the protobuf data structures.
Index ¶
- Constants
- func CalculateCoordsFromStringPosition(evt *pb.GameEvent)
- func Leave(rack alphabet.MachineWord, play alphabet.MachineWord) (alphabet.MachineWord, error)
- func MoveFromEvent(evt *pb.GameEvent, alph *alphabet.Alphabet, board *board.GameBoard) *move.Move
- func NewGameRules(cfg *config.Config, boardLayout []string, lexicon string, ...) (*gamerules, error)
- type Game
- func (g *Game) Alphabet() *alphabet.Alphabet
- func (g *Game) Bag() *alphabet.Bag
- func (g *Game) BingosForNick(nick string) int
- func (g *Game) Board() *board.GameBoard
- func (g *Game) Copy() *Game
- func (g *Game) CreateAndScorePlacementMove(coords string, tiles string, rack string) (*move.Move, error)
- func (g *Game) CurrentSpread() int
- func (g *Game) FirstPlayer() *pb.PlayerInfo
- func (g *Game) Gaddag() *gaddag.SimpleGaddag
- func (g *Game) History() *pb.GameHistory
- func (g *Game) NickOnTurn() string
- func (g *Game) NumPlayers() int
- func (g *Game) PlayMove(m *move.Move, backup bool, addToHistory bool) error
- func (g *Game) PlayScoringMove(coords, word string, addToHistory bool) (*move.Move, error)
- func (g *Game) PlayToTurn(turnnum int) error
- func (g *Game) PlayerOnTurn() int
- func (g *Game) Playing() bool
- func (g *Game) PointsFor(playerIdx int) int
- func (g *Game) PointsForNick(nick string) int
- func (g *Game) RackFor(playerIdx int) *alphabet.Rack
- func (g *Game) RackLettersFor(playerIdx int) string
- func (g *Game) ResetToFirstState()
- func (g *Game) SetNewRules(rules RuleDefiner) error
- func (g *Game) SetPlayerOnTurn(onTurn int)
- func (g *Game) SetPointsFor(player, pts int)
- func (g *Game) SetRackFor(playerIdx int, rack *alphabet.Rack) error
- func (g *Game) SetRacksForBoth(racks []*alphabet.Rack) error
- func (g *Game) SetRandomRack(playerIdx int)
- func (g *Game) SetStateStackLength(length int)
- func (g *Game) SpreadFor(playerIdx int) int
- func (g *Game) StartGame()
- func (g *Game) ThrowRacksIn()
- func (g *Game) ToDisplayText() string
- func (g *Game) Turn() int
- func (g *Game) Uid() string
- func (g *Game) UnplayLastMove()
- type RuleDefiner
Constants ¶
const ( //IdentificationAuthority is the authority that gives out game IDs IdentificationAuthority = "org.aerolith" MacondoCreation = "Created with Macondo" )
Variables ¶
This section is empty.
Functions ¶
func CalculateCoordsFromStringPosition ¶
CalculateCoordsFromStringPosition turns a "position" on the board such as H7 and turns it into a numeric row, col, and direction.
func Leave ¶
func Leave(rack alphabet.MachineWord, play alphabet.MachineWord) (alphabet.MachineWord, error)
Leave calculates the leave from the rack and the made play.
func MoveFromEvent ¶ added in v0.4.4
MoveFromEvent generates a move from an event
Types ¶
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game is the actual internal game structure that controls the entire business logic of the game; drawing, making moves, etc. The two structures above are basically data entities. Note: a Game doesn't care how it is played. It is just rules for gameplay. AI players, human players, etc will play a game outside of the scope of this module.
func NewFromHistory ¶
func NewFromHistory(history *pb.GameHistory, rules RuleDefiner, turnnum int) (*Game, error)
NewFromHistory instantiates a Game from a history, and sets the current turn to the passed in turnnum. It assumes the rules contains the current lexicon in history, if any!
func NewGame ¶
func NewGame(rules RuleDefiner, playerinfo []*pb.PlayerInfo) (*Game, error)
NewGame is how one instantiates a brand new game.
func (*Game) BingosForNick ¶ added in v0.4.4
func (*Game) Copy ¶
Copy creates a deep copy of Game for the most part. The gaddag and alphabet are not deep-copied because these are not expected to change. The history is not copied because this only changes with the main Game, and not these copies. The bag is copied with a NEW random source, as random sources are not thread-safe.
func (*Game) CreateAndScorePlacementMove ¶
func (g *Game) CreateAndScorePlacementMove(coords string, tiles string, rack string) (*move.Move, error)
CreateAndScorePlacementMove creates a *move.Move from the coords and given tiles. It scores the move, calculates the leave, etc. This should be used when a person is interacting with the interface.
func (*Game) CurrentSpread ¶
func (*Game) FirstPlayer ¶
func (g *Game) FirstPlayer() *pb.PlayerInfo
func (*Game) Gaddag ¶
func (g *Game) Gaddag() *gaddag.SimpleGaddag
Gaddag returns this game's gaddag data structure.
func (*Game) History ¶
func (g *Game) History() *pb.GameHistory
func (*Game) NickOnTurn ¶
func (*Game) PlayMove ¶
PlayMove plays a move on the board. This function is meant to be used by simulators as it implements a subset of possible moves. XXX: It doesn't implement special things like challenge bonuses, etc. XXX: Will this still be true, or should this function do it all?
func (*Game) PlayScoringMove ¶
PlayScoringMove plays a move on a board that is described by the coordinates and word only. It returns the move.
func (*Game) PlayToTurn ¶
func (*Game) PlayerOnTurn ¶
func (*Game) PointsForNick ¶
func (*Game) RackLettersFor ¶
RackLettersFor returns a user-visible representation of the player's rack letters
func (*Game) ResetToFirstState ¶
func (g *Game) ResetToFirstState()
ResetToFirstState unplays all moves on the stack.
func (*Game) SetNewRules ¶
func (g *Game) SetNewRules(rules RuleDefiner) error
func (*Game) SetPlayerOnTurn ¶
func (*Game) SetPointsFor ¶
func (*Game) SetRackFor ¶
SetRackFor sets the player's current rack. It throws an error if the rack is impossible to set from the current unseen tiles. It puts tiles back from opponent racks and our own racks, then sets the rack, and finally redraws for opponent.
func (*Game) SetRacksForBoth ¶
SetRacksForBoth sets both racks at the same time.
func (*Game) SetRandomRack ¶
SetRandomRack sets the player's rack to a random rack drawn from the bag. It tosses the current rack back in first. This is used for simulations.
func (*Game) SetStateStackLength ¶
func (*Game) StartGame ¶
func (g *Game) StartGame()
StartGame seeds the random source anew, and starts a game, dealing out tiles to both players.
func (*Game) ThrowRacksIn ¶
func (g *Game) ThrowRacksIn()
ThrowRacksIn throws both players' racks back in the bag.
func (*Game) ToDisplayText ¶
ToDisplayText turns the current state of the game into a displayable string.
func (*Game) UnplayLastMove ¶
func (g *Game) UnplayLastMove()
UnplayLastMove is a tricky but crucial function for any sort of simming / minimax search / etc. It restores the state after playing a move, without having to store a giant amount of data. The alternative is to store the entire game state with every node which quickly becomes unfeasible.
type RuleDefiner ¶
type RuleDefiner interface { Gaddag() *gaddag.SimpleGaddag Board() *board.GameBoard LetterDistribution() *alphabet.LetterDistribution LoadRule(lexiconName, letterDistributionName string) error }
RuleDefiner is an interface that is used for passing a set of rules to a game.