Documentation ¶
Overview ¶
Package cwgame implements the rules for playing a crossword board game. It is heavily dependent on the GameDocument object in protobuf.
Index ¶
- Constants
- func AssignRacks(gdoc *ipc.GameDocument, racks [][]byte, assignEmpty RackAssignBehavior) error
- func EditOldRack(ctx context.Context, cfg *wglconfig.Config, gdoc *ipc.GameDocument, ...) error
- func EventDescription(evt *ipc.GameEvent, rm *tilemapping.TileMapping) string
- func Leave(rack, tilesUsed []tilemapping.MachineLetter) ([]tilemapping.MachineLetter, error)
- func NewGame(cfg *wglconfig.Config, rules *GameRules, ...) (*ipc.GameDocument, error)
- func ProcessGameplayEvent(ctx context.Context, cfg *wglconfig.Config, evt *ipc.ClientGameplayEvent, ...) error
- func ReconcileAllTiles(cfg *wglconfig.Config, gdoc *ipc.GameDocument) error
- func ReplayEvents(ctx context.Context, cfg *wglconfig.Config, gdoc *ipc.GameDocument, ...) error
- func StartGame(ctx context.Context, gdoc *ipc.GameDocument) error
- func ToCGP(cfg *wglconfig.Config, gdoc *ipc.GameDocument) (string, error)
- type FakeNower
- type GameRules
- type GameTimer
- type InvalidWordsError
- type Nower
- type RackAssignBehavior
- type Variant
Constants ¶
const ( RackTileLimit = 7 ExchangePermittedTilesInBag = 7 MaxConsecutiveScorelessTurns = 6 )
const ( VarClassic Variant = "classic" VarWordSmog = "wordsmog" // Redundant information, but we are deciding to treat different board // layouts as different variants. VarClassicSuper = "classic_super" VarWordSmogSuper = "wordsmog_super" )
const UntimedTime = 0
Variables ¶
This section is empty.
Functions ¶
func AssignRacks ¶
func AssignRacks(gdoc *ipc.GameDocument, racks [][]byte, assignEmpty RackAssignBehavior) error
AssignRacks assigns racks to the players. If assignEmpty is true, it will assign a random rack to any players with empty racks in the racks array.
func EditOldRack ¶
func EventDescription ¶
func EventDescription(evt *ipc.GameEvent, rm *tilemapping.TileMapping) string
Return a user-friendly event description. Used for debugging.
func Leave ¶
func Leave(rack, tilesUsed []tilemapping.MachineLetter) ([]tilemapping.MachineLetter, error)
Leave returns the leave after playing or using `tiles` in `rack`. It returns an error if the tile is in the play but not in the rack XXX: This function needs to allocate less.
func NewGame ¶
func NewGame(cfg *wglconfig.Config, rules *GameRules, playerinfo []*ipc.GameDocument_MinimalPlayerInfo) (*ipc.GameDocument, error)
NewGame creates a new GameDocument. The playerinfo array contains the players, which must be in order of who goes first!
func ProcessGameplayEvent ¶
func ProcessGameplayEvent(ctx context.Context, cfg *wglconfig.Config, evt *ipc.ClientGameplayEvent, userID string, gdoc *ipc.GameDocument) error
ProcessGameplayEvent processes a ClientGameplayEvent submitted by userID. The game document is also passed in; the caller should take care to load it from wherever. This function can modify the document in-place. The caller should be responsible for saving it back to whatever store is required if there is no error.
func ReconcileAllTiles ¶
func ReconcileAllTiles(cfg *wglconfig.Config, gdoc *ipc.GameDocument) error
ReconcileAllTiles returns an error if the tiles on the board and on player racks do not match the letter distribution. It is not meant to be used in production, but for debugging purposes only.
func ReplayEvents ¶
func ReplayEvents(ctx context.Context, cfg *wglconfig.Config, gdoc *ipc.GameDocument, evts []*ipc.GameEvent, rememberRacks bool) error
ReplayEvents plays the events on the game document. For simplicity, assume these events replace every event in the game document; i.e., initialize from scratch.
Types ¶
type FakeNower ¶
type FakeNower struct {
// contains filtered or unexported fields
}
FakeNower uses a fake timer. It is used for tests so we don't actually sleep.
func NewFakeNower ¶
type GameTimer ¶
type GameTimer struct{}
GameTimer uses the standard library's `time` package to determine how much time has elapsed in a game.
type InvalidWordsError ¶
type InvalidWordsError struct {
// contains filtered or unexported fields
}
func (*InvalidWordsError) Error ¶
func (e *InvalidWordsError) Error() string
type Nower ¶
type Nower interface { // Now returns a timestamp in milliseconds Now() int64 }
Nower is an interface for determining the current time
type RackAssignBehavior ¶
type RackAssignBehavior int
const ( // NeverAssignEmpty does not assign empty racks NeverAssignEmpty RackAssignBehavior = iota // AlwaysAssignEmpty always assigns empty racks AlwaysAssignEmpty // AssignEmptyIfUnambiguous assigns empty racks if they're the only thing // they can be. For example, if we assign a rack of 5 letters to player 1, // and there are only 6 unassigned letters left, all 6 of these letters // will be assigned to player 2. If there were 8 letters left, none of them // would be assigned to player 2. AssignEmptyIfUnambiguous )