board

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: GPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	CrosswordGameLayout      = "CrosswordGame"
	SuperCrosswordGameLayout = "SuperCrosswordGame"
)
View Source
const (
	// VsEd was a game I played against Ed, under club games 20150127vEd
	// Quackle generates 219 total unique moves with a rack of AFGIIIS
	VsEd VsWho = `` /* 801-byte string literal not displayed */

	// VsMatt was a game I played against Matt Graham, 2018 Lake George tourney
	VsMatt = `` /* 807-byte string literal not displayed */

	// VsJeremy was a game I played against Jeremy Hall, 2018-11 Manhattan tourney
	VsJeremy = `` /* 776-byte string literal not displayed */

	// VsOxy is a constructed game that has a gigantic play available.
	VsOxy = `` /* 777-byte string literal not displayed */

	// VsMatt2 at the 2018-11 Manhattan tourney
	VsMatt2 = `` /* 802-byte string literal not displayed */

	// VsRoy at the 2011 California Open
	VsRoy = `` /* 766-byte string literal not displayed */

	// VsMacondo1 is poor_endgame_timing.gcg
	VsMacondo1 = `` /* 768-byte string literal not displayed */

	// JDvsNB is a test for endgames
	JDvsNB = `` /* 776-byte string literal not displayed */

	// VsAlec at the 2019 Nationals
	VsAlec = `` /* 770-byte string literal not displayed */

	// VsAlec2 same game as above just a couple turns later.
	VsAlec2 = `` /* 768-byte string literal not displayed */

	// VsJoey from Lake George 2019
	VsJoey = `` /* 766-byte string literal not displayed */

	// VsCanik from 2019 Nationals
	VsCanik = `` /* 771-byte string literal not displayed */

	// JoeVsPaul, sample endgame given in the Maven paper
	JoeVsPaul = `` /* 765-byte string literal not displayed */

	// VsJoel from Manhattan November 2019
	// load cgp 1LEMNISCI2L1ER/7O1PAINT1/4A2L1RAVE2/WEDGE2Z1I1R3/4R1JAUNTEd2/4OXO2K5/2YOB3P6/3FAUNAE6/4T3GUY4/6BESTEaD2/7T2HIE2/7H4VUG/2CORMOID6/7O7/7NONIDEAL AAFIRTW/EIQSS 373/393 0 lex NWL18;
	VsJoel = `` /* 769-byte string literal not displayed */

	// Endgame from 2019 Worlds
	// load cgp 4EXODE6/1DOFF1KERATIN1U/1OHO8YEN/1POOJA1B3MEWS/5SQUINTY2A/4RHINO1e3V/2B4C2R3E/GOAT1D1E2ZIN1d/1URACILS2E4/1PIG1S4T4/2L2R4T4/2L2A1GENII3/2A2T1L7/5E1A7/5D1M7 AEEIRUW/V 410/409 0 lex CSW19;
	EldarVsNigel = `` /* 774-byte string literal not displayed */

	TestDupe = `` /* 859-byte string literal not displayed */

	NoahVsMishu = `` /* 774-byte string literal not displayed */

	NoahVsMishu2 = `` /* 773-byte string literal not displayed */

	NoahVsMishu3 = `` /* 772-byte string literal not displayed */

	MavenVsMacondo = `` /* 756-byte string literal not displayed */

	APolishEndgame = `` /* 824-byte string literal not displayed */

	APolishEndgame2 = `` /* 812-byte string literal not displayed */

)
View Source
const MaxBoardDim = 21
View Source
const (
	// TrivialCrossSet allows every possible letter. It is the default
	// state of a square.
	TrivialCrossSet = (1 << tilemapping.MaxAlphabetSize) - 1
)

Variables

View Source
var (
	// CrosswordGameBoard is a board for a fun Crossword Game, featuring lots
	// of wingos and blonks.
	CrosswordGameBoard []string
	// SuperCrosswordGameBoard is a board for a bigger Crossword game, featuring
	// even more wingos and blonks.
	SuperCrosswordGameBoard []string
)
View Source
var (
	// Support standard NO_COLOR env var. Also disable color on windows. Temporary
	// fix for their terminal issues.
	ColorSupport = os.Getenv("NO_COLOR") == "" && runtime.GOOS != "windows"
)

Functions

This section is empty.

Types

type BoardDirection

type BoardDirection uint8
const (
	HorizontalDirection BoardDirection = iota
	VerticalDirection
)

func (BoardDirection) String

func (bd BoardDirection) String() string

type BonusSquare

type BonusSquare byte
const (
	// Bonus4WS is a quadruple word score
	Bonus4WS BonusSquare = '~'
	// Bonus4LS is a quadruple letter score
	Bonus4LS BonusSquare = '^'
	// Bonus3WS is a triple word score
	Bonus3WS BonusSquare = 61 // =  (hex 3D)
	// Bonus3LS is a triple letter score
	Bonus3LS BonusSquare = 34 // "  (hex 22)
	// Bonus2LS is a double letter score
	Bonus2LS BonusSquare = 39 // '  (hex 27)
	// Bonus2WS is a double word score
	Bonus2WS BonusSquare = 45 // -  (hex 2D)

	NoBonus BonusSquare = 32 // space (hex 20)
)

type CrossSet

type CrossSet uint64

A CrossSet is a bit mask of letters that are allowed on a square. It is inherently directional, as it depends on which direction we are generating moves in. If we are generating moves HORIZONTALLY, we check in the VERTICAL cross set to make sure we can play a letter there. Therefore, a VERTICAL cross set is created by looking at the tile(s) above and/or below the relevant square and seeing what letters lead to valid words.

func CrossSetFromString

func CrossSetFromString(letters string, alph *tilemapping.TileMapping) CrossSet

CrossSetFromString is used for testing only and has undefined behavior for multi-char tiles.

func (CrossSet) Allowed

func (c CrossSet) Allowed(letter tilemapping.MachineLetter) bool

func (*CrossSet) Clear added in v0.4.5

func (c *CrossSet) Clear()

func (*CrossSet) Set added in v0.4.5

func (c *CrossSet) Set(letter tilemapping.MachineLetter)

func (*CrossSet) SetAll added in v0.4.5

func (c *CrossSet) SetAll()

type GameBoard

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

GameBoard will store a one-dimensional array of tiles played.

func MakeBoard

func MakeBoard(desc []string) *GameBoard

MakeBoard creates a board from a description string. Assumption: strings are ASCII.

func (*GameBoard) Clear

func (g *GameBoard) Clear()

Clear clears the board.

func (*GameBoard) ClearAllCrosses

func (g *GameBoard) ClearAllCrosses()

ClearAllCrosses disallows all letters on all squares (more or less).

func (*GameBoard) ClearCrossSet

func (g *GameBoard) ClearCrossSet(row int, col int, dir BoardDirection)

func (*GameBoard) Copy added in v0.2.11

func (g *GameBoard) Copy() *GameBoard

Copy returns a deep copy of this board.

func (*GameBoard) CopyFrom added in v0.2.11

func (g *GameBoard) CopyFrom(b *GameBoard)

CopyFrom copies the squares and other info from b back into g.

func (*GameBoard) Dim

func (g *GameBoard) Dim() int

Dim is the dimension of the board. It assumes the board is square.

func (*GameBoard) Equals added in v0.2.11

func (g *GameBoard) Equals(g2 *GameBoard) bool

Equals checks the boards for equality. Two boards are equal if all the squares are equal. This includes anchors, letters, and cross-sets.

func (*GameBoard) ErrorIfIllegalPlay added in v0.3.0

func (g *GameBoard) ErrorIfIllegalPlay(row, col int, vertical bool,
	word tilemapping.MachineWord) error

ErrorIfIllegalPlay returns an error if the play is illegal, or nil otherwise. We are not checking the actual validity of the word, but whether it is a legal Crossword Game move.

func (*GameBoard) FormedWords added in v0.4.4

func (g *GameBoard) FormedWords(m *move.Move) ([]tilemapping.MachineWord, error)

FormedWords returns an array of all machine words formed by this move. The move is assumed to be of type Play

func (*GameBoard) GetBonus

func (g *GameBoard) GetBonus(row int, col int) BonusSquare

func (*GameBoard) GetCrossScore

func (g *GameBoard) GetCrossScore(row int, col int, dir BoardDirection) int

func (*GameBoard) GetCrossScoreIdx added in v0.8.7

func (g *GameBoard) GetCrossScoreIdx(pos int, dir BoardDirection) int

func (*GameBoard) GetCrossSet

func (g *GameBoard) GetCrossSet(row int, col int, dir BoardDirection) CrossSet

func (*GameBoard) GetCrossSetIdx added in v0.8.7

func (g *GameBoard) GetCrossSetIdx(pos int, dir BoardDirection) CrossSet

func (*GameBoard) GetLetter

func (g *GameBoard) GetLetter(row int, col int) tilemapping.MachineLetter

func (*GameBoard) GetLetterMultiplier added in v0.8.7

func (g *GameBoard) GetLetterMultiplier(sqIdx int) int

func (*GameBoard) GetSqIdx added in v0.8.7

func (g *GameBoard) GetSqIdx(row, col int) int

func (*GameBoard) GetSquares added in v0.4.10

func (g *GameBoard) GetSquares() []tilemapping.MachineLetter

func (*GameBoard) GetTilesPlayed added in v0.4.5

func (g *GameBoard) GetTilesPlayed() int

func (*GameBoard) GetWordMultiplier added in v0.8.7

func (g *GameBoard) GetWordMultiplier(sqIdx int) int

func (*GameBoard) HasLetter added in v0.4.5

func (g *GameBoard) HasLetter(row int, col int) bool

func (*GameBoard) IsAnchor

func (g *GameBoard) IsAnchor(row int, col int, dir BoardDirection) bool

IsAnchor returns whether the row/col pair is an anchor in the given direction.

func (*GameBoard) IsEmpty

func (g *GameBoard) IsEmpty() bool

IsEmpty returns if the board is empty.

func (*GameBoard) LeftAndRightEmpty added in v0.4.5

func (g *GameBoard) LeftAndRightEmpty(row int, col int) bool

LeftAndRightEmpty returns true if the squares at col - 1 and col + 1 on this row are empty, checking carefully for boundary conditions.

func (*GameBoard) PlaceMoveTiles added in v0.4.5

func (g *GameBoard) PlaceMoveTiles(m *move.Move)

func (*GameBoard) PlayMove

func (g *GameBoard) PlayMove(m *move.Move)

PlayMove plays a move on a board. It must place tiles on the board, regenerate cross-sets and cross-points, and recalculate anchors.

func (*GameBoard) PlaySmallMove added in v0.8.7

func (g *GameBoard) PlaySmallMove(m *tinymove.SmallMove, moveTiles *[MaxBoardDim]tilemapping.MachineLetter, rack *tilemapping.Rack)

PlaySmallMove plays a SmallMove on a board. We unroll the PlaceMoveTiles and updateAnchorsForMove here with some modifications.

func (*GameBoard) PosExists added in v0.4.5

func (g *GameBoard) PosExists(row int, col int) bool

func (*GameBoard) ResetCrossScores added in v0.4.9

func (g *GameBoard) ResetCrossScores()

func (*GameBoard) RestoreFromCopy added in v0.4.5

func (g *GameBoard) RestoreFromCopy()

func (*GameBoard) ScoreWord added in v0.3.0

func (g *GameBoard) ScoreWord(word tilemapping.MachineWord, row, col, tilesPlayed int,
	crossDir BoardDirection, ld *tilemapping.LetterDistribution) int

ScoreWord scores the move at the given row and column. Note that this function is called when the board is potentially transposed, so we assume the row stays static as we iterate through the letters of the word.

func (*GameBoard) SetAllCrosses

func (g *GameBoard) SetAllCrosses()

SetAllCrosses sets the cross sets of every square to every acceptable letter.

func (*GameBoard) SetCrossScore added in v0.4.9

func (g *GameBoard) SetCrossScore(row, col, score int, dir BoardDirection)

func (*GameBoard) SetCrossSet added in v0.4.9

func (g *GameBoard) SetCrossSet(row int, col int, cs CrossSet,
	dir BoardDirection)

func (*GameBoard) SetCrossSetLetter

func (g *GameBoard) SetCrossSetLetter(row int, col int, dir BoardDirection,
	ml tilemapping.MachineLetter)

func (*GameBoard) SetLetter

func (g *GameBoard) SetLetter(row int, col int, letter tilemapping.MachineLetter)

func (*GameBoard) SetRow

func (b *GameBoard) SetRow(rowNum int, letters string, alph *tilemapping.TileMapping) []tilemapping.MachineLetter

SetRow sets the row in board to the passed-in letters array. Callers should use a " " (space character) for an empty space

func (*GameBoard) SetRowMLs added in v0.8.6

func (b *GameBoard) SetRowMLs(rowNum int, mls []tilemapping.MachineLetter) []tilemapping.MachineLetter

func (*GameBoard) SetToGame

func (b *GameBoard) SetToGame(alph *tilemapping.TileMapping, game VsWho) *TilesInPlay

SetToGame sets the board to a specific game in progress. It is used to generate test cases.

func (*GameBoard) TestSetTilesPlayed added in v0.4.5

func (g *GameBoard) TestSetTilesPlayed(n int)

func (*GameBoard) TilesPlayed added in v0.4.0

func (g *GameBoard) TilesPlayed() int

func (*GameBoard) ToDisplayText

func (g *GameBoard) ToDisplayText(alph *tilemapping.TileMapping) string

func (*GameBoard) ToFEN added in v0.7.0

func (g *GameBoard) ToFEN(alph *tilemapping.TileMapping) string

ToFEN converts the game board to a FEN string, which is the board component of the CGP data format. See cgp directory for more info.

func (*GameBoard) Transpose

func (g *GameBoard) Transpose()

Transpose the board in-place. We should copy transposed boards in the future.

func (*GameBoard) TraverseBackwardsForScore added in v0.4.5

func (g *GameBoard) TraverseBackwardsForScore(row int, col int, ld *tilemapping.LetterDistribution) int

func (*GameBoard) UnplaceMoveTiles added in v0.4.5

func (g *GameBoard) UnplaceMoveTiles(m *move.Move)

func (*GameBoard) UpdateAllAnchors

func (g *GameBoard) UpdateAllAnchors()

func (*GameBoard) WordEdge added in v0.4.5

func (g *GameBoard) WordEdge(row int, col int, dir WordDirection) int

WordEdge finds the edge of a word on the board, returning the column.

type TilesInPlay

type TilesInPlay struct {
	OnBoard []tilemapping.MachineLetter
	Rack1   []tilemapping.MachineLetter
	Rack2   []tilemapping.MachineLetter
}

type VsWho

type VsWho string

VsWho is a string representation of a board.

type WordDirection

type WordDirection int
const (
	LeftDirection  WordDirection = -1
	RightDirection WordDirection = 1
)

Jump to

Keyboard shortcuts

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