movegen

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 12 Imported by: 2

Documentation

Overview

Package movegen contains all the move-generating functions. It makes heavy use of the GADDAG. Implementation notes: - Is the specification in the paper a bit buggy? Basically, if I assume an anchor is the leftmost tile of a word, the way the algorithm works, it will create words blindly. For example, if I have a word FIRE on the board, and I have the letter E on my rack, and I specify F as the anchor, it will create the word EF! (Ignoring the fact that IRE is on the board) You can see this by just stepping through the algorithm. It seems that anchors can only be on the rightmost tile of a word

Index

Constants

This section is empty.

Variables

View Source
var SmallPlaySlicePool = sync.Pool{
	New: func() interface{} {
		s := make([]tinymove.SmallMove, 0)
		return &s
	},
}

Functions

func AllPlaysRecorder added in v0.4.9

func AllPlaysRecorder(gen *GordonGenerator, rack *tilemapping.Rack, leftstrip, rightstrip int, t move.MoveType, score int)

func AllPlaysSmallRecorder added in v0.8.7

func AllPlaysSmallRecorder(gen *GordonGenerator, rack *tilemapping.Rack, leftstrip, rightstrip int, t move.MoveType, score int)

AllPlaysSmallRecorder is a recorder that records all plays, but as "SmallMove"s, which allocate much less and are smaller overall than a regular move.Move

func NullPlayRecorder added in v0.4.9

func NullPlayRecorder(gen *GordonGenerator, a *tilemapping.Rack, leftstrip, rightstrip int, t move.MoveType, score int)

func TopPlayOnlyRecorder added in v0.4.9

func TopPlayOnlyRecorder(gen *GordonGenerator, rack *tilemapping.Rack, leftstrip, rightstrip int, t move.MoveType, score int)

TopPlayOnlyRecorder is a heavily optimized, ugly function to avoid allocating a lot of moves just to throw them out. It only records the very top move.

Types

type GordonGenerator added in v0.2.0

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

GordonGenerator is the main move generation struct. It implements Steven A. Gordon's algorithm from his paper "A faster Scrabble Move Generation Algorithm"

func NewGordonGenerator added in v0.2.0

func NewGordonGenerator(gd gaddag.WordGraph, board *board.GameBoard,
	ld *tilemapping.LetterDistribution) *GordonGenerator

NewGordonGenerator returns a Gordon move generator.

func (*GordonGenerator) AtLeastOneTileMove added in v0.7.0

func (gen *GordonGenerator) AtLeastOneTileMove(rack *tilemapping.Rack) bool

AtLeastOneTileMove generates moves. We don't care what they are; return true if there is at least one move that plays tiles, false otherwise.

func (*GordonGenerator) GADDAG added in v0.7.0

func (gen *GordonGenerator) GADDAG() *kwg.KWG

func (*GordonGenerator) GenAll added in v0.2.0

func (gen *GordonGenerator) GenAll(rack *tilemapping.Rack, addExchange bool) []*move.Move

GenAll generates all moves on the board. It assumes anchors have already been updated, as well as cross-sets / cross-scores.

func (*GordonGenerator) Plays added in v0.2.0

func (gen *GordonGenerator) Plays() []*move.Move

Plays returns the generator's generated plays.

func (*GordonGenerator) SetEquityCalculators added in v0.5.0

func (gen *GordonGenerator) SetEquityCalculators(calcs []equity.EquityCalculator)

func (*GordonGenerator) SetGame added in v0.4.9

func (gen *GordonGenerator) SetGame(g *game.Game)

func (*GordonGenerator) SetGenPass added in v0.7.0

func (gen *GordonGenerator) SetGenPass(p bool)

func (*GordonGenerator) SetMaxTileUsage added in v0.8.0

func (gen *GordonGenerator) SetMaxTileUsage(t int)

func (*GordonGenerator) SetPlayRecorder added in v0.4.9

func (gen *GordonGenerator) SetPlayRecorder(pr PlayRecorderFunc)

func (*GordonGenerator) SetSortingParameter added in v0.2.0

func (gen *GordonGenerator) SetSortingParameter(s SortBy)

SetSortingParameter tells the play sorter to sort by score, equity, or perhaps other things. This is useful for the endgame solver, which does not care about equity.

func (*GordonGenerator) SmallPlays added in v0.8.7

func (gen *GordonGenerator) SmallPlays() []tinymove.SmallMove

SmallPlays returns the generator's generated SmallPlays

type MoveGenerator added in v0.2.11

type MoveGenerator interface {
	GenAll(rack *tilemapping.Rack, addExchange bool) []*move.Move
	SetSortingParameter(s SortBy)
	Plays() []*move.Move
	SmallPlays() []tinymove.SmallMove
	SetPlayRecorder(pf PlayRecorderFunc)
	SetEquityCalculators([]equity.EquityCalculator)
	AtLeastOneTileMove(rack *tilemapping.Rack) bool
	SetMaxTileUsage(int)
	SetGenPass(bool)
}

MoveGenerator is a generic interface for generating moves.

type PlayRecorderFunc added in v0.4.9

type PlayRecorderFunc func(*GordonGenerator, *tilemapping.Rack, int, int, move.MoveType, int)

type SortBy added in v0.2.0

type SortBy int
const (
	SortByScore SortBy = iota
	SortByNone
)

Jump to

Keyboard shortcuts

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