game

package
v0.4.4-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2020 License: GPL-3.0 Imports: 17 Imported by: 10

Documentation

Overview

Package game encapsulates the main mechanics for a Crossword Game. It interacts heavily with the protobuf data structures.

Index

Constants

View Source
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

func CalculateCoordsFromStringPosition(evt *pb.GameEvent)

CalculateCoordsFromStringPosition turns a "position" on the board such as H7 and turns it into a numeric row, col, and direction.

func Leave

Leave calculates the leave from the rack and the made play.

func MoveFromEvent added in v0.4.4

func MoveFromEvent(evt *pb.GameEvent, alph *alphabet.Alphabet, board *board.GameBoard) *move.Move

MoveFromEvent generates a move from an event

func NewGameRules

func NewGameRules(cfg *config.Config, boardLayout []string, lexicon string,
	letterDistributionName string) (*gamerules, error)

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) Alphabet

func (g *Game) Alphabet() *alphabet.Alphabet

func (*Game) Bag

func (g *Game) Bag() *alphabet.Bag

Bag returns the current bag

func (*Game) BingosForNick added in v0.4.4

func (g *Game) BingosForNick(nick string) int

func (*Game) Board

func (g *Game) Board() *board.GameBoard

Board returns the current board state.

func (*Game) Copy

func (g *Game) Copy() *Game

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 (g *Game) CurrentSpread() int

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 (g *Game) NickOnTurn() string

func (*Game) NumPlayers

func (g *Game) NumPlayers() int

NumPlayers is always 2.

func (*Game) PlayMove

func (g *Game) PlayMove(m *move.Move, backup bool, addToHistory bool) error

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

func (g *Game) PlayScoringMove(coords, word string, addToHistory bool) (*move.Move, error)

PlayScoringMove plays a move on a board that is described by the coordinates and word only. It returns the move.

func (*Game) PlayToTurn

func (g *Game) PlayToTurn(turnnum int) error

func (*Game) PlayerOnTurn

func (g *Game) PlayerOnTurn() int

func (*Game) Playing

func (g *Game) Playing() bool

func (*Game) PointsFor

func (g *Game) PointsFor(playerIdx int) int

PointsFor returns the number of points for the given player

func (*Game) PointsForNick

func (g *Game) PointsForNick(nick string) int

func (*Game) RackFor

func (g *Game) RackFor(playerIdx int) *alphabet.Rack

RackFor returns the rack for the player with the passed-in index

func (*Game) RackLettersFor

func (g *Game) RackLettersFor(playerIdx int) string

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 (g *Game) SetPlayerOnTurn(onTurn int)

func (*Game) SetPointsFor

func (g *Game) SetPointsFor(player, pts int)

func (*Game) SetRackFor

func (g *Game) SetRackFor(playerIdx int, rack *alphabet.Rack) error

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

func (g *Game) SetRacksForBoth(racks []*alphabet.Rack) error

SetRacksForBoth sets both racks at the same time.

func (*Game) SetRandomRack

func (g *Game) SetRandomRack(playerIdx int)

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 (g *Game) SetStateStackLength(length int)

func (*Game) SpreadFor

func (g *Game) SpreadFor(playerIdx int) int

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

func (g *Game) ToDisplayText() string

ToDisplayText turns the current state of the game into a displayable string.

func (*Game) Turn

func (g *Game) Turn() int

func (*Game) Uid

func (g *Game) Uid() 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL