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, error)
- type BackupMode
- type Game
- func (g *Game) AddFinalScoresToHistory()
- 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) ChallengeEvent(addlBonus int, millis int) (bool, error)
- func (g *Game) Config() *config.Config
- 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) EventFromMove(m *move.Move) *pb.GameEvent
- func (g *Game) FirstPlayer() *pb.PlayerInfo
- func (g *Game) History() *pb.GameHistory
- func (g *Game) LastEvent() *pb.GameEvent
- func (g *Game) LastWordsFormed() []alphabet.MachineWord
- func (g *Game) Lexicon() lexicon.Lexicon
- func (g *Game) LexiconName() string
- func (g *Game) NextPlayer() int
- func (g *Game) NickOnTurn() string
- func (g *Game) NumPlayers() int
- func (g *Game) PlayLatestEvent() error
- func (g *Game) PlayMove(m *move.Move, addToHistory bool, millis int) error
- func (g *Game) PlayScoringMove(coords, word string, addToHistory bool) (*move.Move, error)
- func (g *Game) PlayToTurn(turnnum int) error
- func (g *Game) PlayerIDOnTurn() string
- func (g *Game) PlayerOnTurn() int
- func (g *Game) Playing() pb.PlayState
- 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) RecalculateBoard()
- func (g *Game) ResetToFirstState()
- func (g *Game) Rules() *GameRules
- func (g *Game) ScorelessTurns() int
- func (g *Game) SetBackupMode(m BackupMode)
- func (g *Game) SetChallengeRule(rule pb.ChallengeRule)
- func (g *Game) SetHistory(h *pb.GameHistory)
- func (g *Game) SetMaxScorelessTurns(m int)
- func (g *Game) SetNextFirst(first int)
- func (g *Game) SetPlayerOnTurn(onTurn int)
- func (g *Game) SetPlaying(s pb.PlayState)
- 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) TurnsForNick(nick string) int
- func (g *Game) Uid() string
- func (g *Game) UnplayLastMove()
- func (g *Game) ValidateMove(m *move.Move) ([]alphabet.MachineWord, error)
- type GameRules
- func (g GameRules) Board() *board.GameBoard
- func (g GameRules) BoardName() string
- func (g GameRules) Config() *config.Config
- func (g GameRules) CrossSetGen() cross_set.Generator
- func (g GameRules) LetterDistribution() *alphabet.LetterDistribution
- func (g GameRules) LetterDistributionName() string
- func (g GameRules) Lexicon() lexicon.Lexicon
- func (g GameRules) LexiconName() string
- func (g GameRules) Variant() Variant
- type Variant
Constants ¶
const ( //IdentificationAuthority is the authority that gives out game IDs IdentificationAuthority = "io.woogles" MacondoCreation = "Created with Macondo" ExchangeLimit = 8 RackTileLimit = 8 DefaultMaxScorelessTurns = 6 )
const ( VarClassic Variant = "classic" VarWordSmog = "wordsmog" VarExtendedRack = "extrack" // Redundant information, but we are deciding to treat different board // layouts as different variants. VarClassicSuper = "classic_super" VarWordSmogSuper = "wordsmog_super" )
const ( CrossScoreOnly = "cs" CrossScoreAndSet = "css" )
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.
Types ¶
type BackupMode ¶
type BackupMode int
const ( // NoBackup never performs game backups. It can be used for autoplay // that has absolutely no input. NoBackup BackupMode = iota // SimulationMode keeps a stack of game copies, using these for doing // endgame and other types of simulations. SimulationMode // InteractiveGameplayMode keeps just one backup after every turn. This is needed // in order to get challenges working, which would roll back the game to // an earlier state if a word is challenged off. InteractiveGameplayMode )
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 ¶
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 *GameRules, playerinfo []*pb.PlayerInfo) (*Game, error)
NewGame is how one instantiates a brand new game.
func (*Game) AddFinalScoresToHistory ¶
func (g *Game) AddFinalScoresToHistory()
AddFinalScoresToHistory adds the final scores and winner to the history.
func (*Game) BingosForNick ¶
func (*Game) ChallengeEvent ¶
ChallengeEvent should only be called if there is a history of events. It has the logic for appending challenge events and calculating scores properly. Note that this event can change the history of the game, including things like reset gameEnded back to false (for example if someone plays out with a phony). Return playLegal, error
func (*Game) Copy ¶
Copy creates a deep copy of Game for the most part. The lexicon 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.
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) History ¶
func (g *Game) History() *pb.GameHistory
func (*Game) LastWordsFormed ¶
func (g *Game) LastWordsFormed() []alphabet.MachineWord
func (*Game) LexiconName ¶
func (*Game) NextPlayer ¶
func (*Game) NickOnTurn ¶
func (*Game) PlayLatestEvent ¶
PlayLatestEvent "plays" the latest event on the board. This is used for replaying a game from a GCG.
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, and by remote gameplay engines as much as possible. If the millis argument is passed in, it adds this value to the history as the time remaining for the user (when they played the move).
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) PlayerIDOnTurn ¶
func (*Game) PlayerOnTurn ¶
func (*Game) PointsForNick ¶
func (*Game) RackLettersFor ¶
RackLettersFor returns a user-visible representation of the player's rack letters
func (*Game) RecalculateBoard ¶
func (g *Game) RecalculateBoard()
func (*Game) ResetToFirstState ¶
func (g *Game) ResetToFirstState()
ResetToFirstState unplays all moves on the stack.
func (*Game) ScorelessTurns ¶
func (*Game) SetBackupMode ¶
func (g *Game) SetBackupMode(m BackupMode)
func (*Game) SetChallengeRule ¶
func (g *Game) SetChallengeRule(rule pb.ChallengeRule)
SetChallengeRule sets the challenge rule for a game. The game must already be started with StartGame above (call immediately afterwards). It would default to the 0 state (VOID) otherwise.
func (*Game) SetHistory ¶
func (g *Game) SetHistory(h *pb.GameHistory)
func (*Game) SetMaxScorelessTurns ¶
func (*Game) SetNextFirst ¶
SetNextFirst sets the player going first to the passed-in value. This will take effect the next time StartGame is called.
func (*Game) SetPlayerOnTurn ¶
func (*Game) SetPlaying ¶
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 starts a game anew, 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) TurnsForNick ¶
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.
func (*Game) ValidateMove ¶
ValidateMove validates the given move. It is meant to be used to validate user input games (perhaps from live play or GCGs). It does not check the validity of the words formed (unless the challenge rule is VOID), but it validates that the rules of the game are followed. It returns an array of `alphabet.MachineWord`s formed, or an error if the play is not game legal.
type GameRules ¶
type GameRules struct {
// contains filtered or unexported fields
}
GameRules is a simple struct that encapsulates the instantiated objects needed to actually play a game.
func NewBasicGameRules ¶
func (GameRules) CrossSetGen ¶
func (GameRules) LetterDistribution ¶
func (g GameRules) LetterDistribution() *alphabet.LetterDistribution
func (GameRules) LetterDistributionName ¶
func (GameRules) LexiconName ¶
type Variant ¶
type Variant string
func HistoryToVariant ¶
func HistoryToVariant(h *pb.GameHistory) (boardLayoutName, letterDistributionName string, variant Variant)
HistoryToVariant takes in a game history and returns the board configuration and letter distribution name.