Documentation
¶
Overview ¶
Package backgammon is a pure-Go backgammon rules engine — no protocol, no I/O, no dependencies beyond the standard library. Turn validation is generate-all-legal-turns + membership (LegalTurns / Validate), which encodes the awkward tabletop obligations (use both dice if possible; if only one can be played, the larger) without special cases — well suited to both-sides-validate multiplayer where neither end is trusted. Doubling cube: not yet implemented.
Extracted from https://github.com/richardwooding/kibitz
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrIllegalTurn = errors.New("backgammon: illegal turn")
Functions ¶
func LegalTurns ¶
LegalTurns generates every complete legal turn for c with the given dice. A turn is an ordered hop sequence; the tabletop obligations fall out of the construction:
- all returned sequences have maximal length (use both dice if you can),
- when only one die can be played and either could be, only the larger die's hops are returned,
- an empty single sequence means no legal moves (a dance).
Types ¶
type Board ¶
type Board struct {
Points [25]int8 `cbor:"1,keyasint"` // index 0 unused
Bar [2]int8 `cbor:"2,keyasint"`
Off [2]int8 `cbor:"3,keyasint"`
}
Board is the shared position. Points are numbered 1..24 in WHITE's numbering (Black's point p is 25-p); positive counts are White checkers, negative are Black.
type Color ¶
type Color int8
Color identifies a player. White moves from point 24 toward 1 (in its own numbering) and bears off from 1..6; Black mirrors.