cwgame

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

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

View Source
const (
	RackTileLimit                = 7
	ExchangePermittedTilesInBag  = 7
	MaxConsecutiveScorelessTurns = 6
)
View Source
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"
)
View Source
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 EditOldRack(ctx context.Context, cfg *wglconfig.Config, gdoc *ipc.GameDocument, evtNumber uint32, rack []byte) error

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.

func StartGame

func StartGame(ctx context.Context, gdoc *ipc.GameDocument) error

func ToCGP

func ToCGP(cfg *wglconfig.Config, gdoc *ipc.GameDocument) (string, error)

ToCGP converts the game to a CGP string.

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

func NewFakeNower(f int64) *FakeNower

func (FakeNower) Now

func (f FakeNower) Now() int64

Now returns now's value

func (*FakeNower) Sleep

func (f *FakeNower) Sleep(t int64)

Sleep simulates a sleep.

type GameRules

type GameRules struct {
	// contains filtered or unexported fields
}

func NewBasicGameRules

func NewBasicGameRules(lexicon, boardLayout, letterDist string, challengeRule ipc.ChallengeRule,
	variant Variant, seconds []int, overtimeMins int, increment int, untimed bool) *GameRules

type GameTimer

type GameTimer struct{}

GameTimer uses the standard library's `time` package to determine how much time has elapsed in a game.

func (GameTimer) Now

func (g GameTimer) Now() int64

Now returns the current timestamp in milliseconds.

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
)

type Variant

type Variant string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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