Documentation
¶
Overview ¶
Package bot plays TwixT. One alpha-beta search backs three effort tiers and the hint feature; the tiers differ in budget, depth, candidate width and how much of the evaluation they are allowed to see.
Index ¶
Constants ¶
const NoChain = -1
NoChain is the Dist of a side that can no longer join its two borders at all, because the opponent's links seal every route. It is a distinct value rather than a large number so that a caller cannot mistake it for a peg count.
Variables ¶
var ErrNoMove = errors.New("bot: no legal placement available")
ErrNoMove reports a position where the bot has nowhere to play.
Functions ¶
func TierSummary ¶
TierSummary returns the one-line description of a named tier, for help text and shell completion. An unknown name returns the empty string.
Types ¶
type Bot ¶
type Bot interface {
Tier() Tier
// Move returns the hole to play. It never returns an illegal move.
//
// A deadline or a cancellation on ctx cuts the search short and Move
// returns the best move it had reached, which is how a per-move budget is
// enforced; it is not an error, and even an already-cancelled context
// yields a legal move chosen by the ordering heuristic. An error means the
// position genuinely has no move: the game is over, or there is nowhere
// left to play.
Move(ctx context.Context, g *game.Game) (game.Point, error)
// Hint explains the move the bot would consider best for the side to move.
// A hint is always computed with the strongest settings the package has,
// whatever tier is playing, so that a beginner-tier game does not also give
// beginner-tier advice.
Hint(ctx context.Context, g *game.Game) (Hint, error)
}
Bot plays one side of a game.
A Bot carries the working state of its search and is not safe for concurrent use: give each game its own Bot.
type Hint ¶
type Hint struct {
Move game.Point
// Headline is one short line: what to play.
Headline string
// Detail is one to three short sentences saying why, in terms of the
// numbers the search actually measured.
Detail string
// Highlight lists the holes the explanation refers to, for the board to
// mark.
Highlight []game.Point
}
Hint is a recommended move together with an explanation derived from the search that found it.
type Terms ¶
type Terms struct {
// Dist is the number of pegs the side still needs to finish its chain.
// Zero means the chain is complete; NoChain means there is no route left.
Dist int
// OppDist is the same count for the opponent.
OppDist int
// Bottlenecks counts the holes every one of the side's cheapest chains has
// to run through, so a single opposing peg would set the plan back. Zero
// means every step of the plan has an alternative.
Bottlenecks int
// OppBottlenecks is the same count for the opponent.
OppBottlenecks int
// Ground is how much more of the board the side can reach cheaply than the
// opponent, in parts per thousand of the usable holes. It is negative when
// the opponent has the wider reach.
Ground int
}
Terms is the decomposition of a static evaluation, in the units the hint feature talks about. Every score the search produces at a leaf is a function of these numbers and nothing else, which is what makes a derived explanation checkable.