Documentation ¶
Overview ¶
Package bgammon provides an interface for connecting to the bgammon.org online backgammon server.
Index ¶
- Constants
- func DecodeEvent(message []byte) (interface{}, error)
- func FlipMoves(moves [][]int8, player int8, variant int8) [][]int8
- func FlipSpace(space int8, player int8, variant int8) int8
- func FormatAndFlipMoves(moves [][]int8, player int8, variant int8) []byte
- func FormatMoves(moves [][]int8) []byte
- func FormatSpace(space int8) []byte
- func HomeRange(player int8, variant int8) (from int8, to int8)
- func IterateSpaces(from int8, to int8, variant int8, f func(space int8, spaceCount int8))
- func NewBoard(variant int8) []int8
- func OpponentCheckers(checkers int8, player int8) int8
- func ParseSpace(space string) int8
- func PlayerCheckers(checkers int8, player int8) int8
- func RollForMove(from int8, to int8, player int8, variant int8) int8
- func SortMoves(moves [][]int8)
- func SpaceDiff(from int8, to int8, variant int8) int8
- func ValidSpace(space int8) bool
- type Client
- type Command
- type Event
- type EventBoard
- type EventFailedJoin
- type EventFailedLeave
- type EventFailedMove
- type EventFailedOk
- type EventFailedRoll
- type EventHelp
- type EventHistory
- type EventJoined
- type EventLeft
- type EventList
- type EventMoved
- type EventNotice
- type EventPing
- type EventReplay
- type EventRolled
- type EventSay
- type EventSettings
- type EventType
- type EventWelcome
- type EventWin
- type Game
- func (g *Game) AddLocalMove(move []int8) bool
- func (g *Game) AddMoves(moves [][]int8, local bool) (bool, [][]int8)
- func (g *Game) BoardState(player int8, local bool) []byte
- func (g *Game) Copy(shallow bool) *Game
- func (g *Game) DiceRolls() []int8
- func (g *Game) ExpandMove(move []int8, currentSpace int8, moves [][]int8, local bool) ([][]int8, bool)
- func (g *Game) HaveBearOffDiceRoll(diff int8) int8
- func (g *Game) HaveDiceRoll(from int8, to int8) int8
- func (g *Game) LegalMoves(local bool) [][]int8
- func (g *Game) MayBearOff(player int8, local bool) bool
- func (g *Game) NextPartialTurn(player int8)
- func (g *Game) NextTurn(reroll bool)
- func (g *Game) PartialHandled() bool
- func (g *Game) PartialTime() int
- func (g *Game) PartialTurn() int8
- func (g *Game) RenderSpace(player int8, space int8, spaceValue int8, legalMoves [][]int8) []byte
- func (g *Game) Reset()
- func (g *Game) SecondHalf(player int8, local bool) bool
- func (g *Game) SetPartialHandled(handled bool)
- func (g *Game) TabulaBoard() (tabula.Board, bool)
- type GameListing
- type GameState
- func (g *GameState) LocalPlayer() Player
- func (g *GameState) MayChooseRoll() bool
- func (g *GameState) MayDouble() bool
- func (g *GameState) MayOK() bool
- func (g *GameState) MayReset() bool
- func (g *GameState) MayResign() bool
- func (g *GameState) MayRoll() bool
- func (g *GameState) OpponentPlayer() Player
- func (g *GameState) Pips(player int8) int
- func (g *GameState) SpaceAt(x int8, y int8) int8
- type HistoryMatch
- type Player
Constants ¶
const ( SpaceHomePlayer int8 = 0 // Current player's home. SpaceHomeOpponent int8 = 25 // Opponent player's home. SpaceBarPlayer int8 = 26 // Current player's bar. SpaceBarOpponent int8 = 27 // Opponent player's bar. )
const ( CommandLogin = "login" // Log in with username and password, or as a guest. CommandLoginJSON = "loginjson" // Log in with username and password, or as a guest, and enable JSON messages. CommandRegister = "register" // Register an account. CommandRegisterJSON = "registerjson" // Register an account and enable JSON messages. CommandResetPassword = "resetpassword" // Request password reset link via email. CommandPassword = "password" // Change password. CommandSet = "set" // Change account setting. CommandReplay = "replay" // Retrieve replay. CommandHistory = "history" // Retrieve match history. CommandHelp = "help" // Print help information. CommandJSON = "json" // Enable or disable JSON formatted messages. CommandSay = "say" // Send chat message. CommandList = "list" // List available matches. CommandCreate = "create" // Create match. CommandJoin = "join" // Join match. CommandLeave = "leave" // Leave match. CommandDouble = "double" // Offer double to opponent. CommandResign = "resign" // Decline double offer and resign game. CommandRoll = "roll" // Roll dice. CommandMove = "move" // Move checkers. CommandReset = "reset" // Reset checker movement. CommandOk = "ok" // Confirm checker movement and pass turn to next player. CommandRematch = "rematch" // Confirm checker movement and pass turn to next player. CommandBoard = "board" // Print current board state in human-readable form. CommandPong = "pong" // Response to server ping. CommandDisconnect = "disconnect" // Disconnect from server. )
const ( EventTypeWelcome = "welcome" EventTypeHelp = "help" EventTypePing = "ping" EventTypeNotice = "notice" EventTypeSay = "say" EventTypeList = "list" EventTypeJoined = "joined" EventTypeFailedJoin = "failedjoin" EventTypeLeft = "left" EventTypeFailedLeave = "failedleave" EventTypeBoard = "board" EventTypeRolled = "rolled" EventTypeFailedRoll = "failedroll" EventTypeMoved = "moved" EventTypeFailedMove = "failedmove" EventTypeFailedOk = "failedok" EventTypeWin = "win" EventTypeSettings = "settings" EventTypeReplay = "replay" EventTypeHistory = "history" )
const ( SpeedSlow int8 = 0 SpeedMedium int8 = 1 SpeedFast int8 = 2 SpeedInstant int8 = 3 )
const ( VariantBackgammon int8 = 0 VariantAceyDeucey int8 = 1 VariantTabula int8 = 2 )
const BoardSpaces = 28
BoardSpaces is the total number of spaces needed to represent a backgammon board.
Variables ¶
This section is empty.
Functions ¶
func DecodeEvent ¶
func FormatMoves ¶
func FormatSpace ¶
func IterateSpaces ¶
func NewBoard ¶
NewBoard returns a new backgammon board represented as integers. Positive integers represent player 1's checkers and negative integers represent player 2's checkers. The board's space numbering is always from the perspective of the current player (i.e. the 1 space will always be in the current player's home board).
func OpponentCheckers ¶
func ParseSpace ¶
func PlayerCheckers ¶
func RollForMove ¶
RollForMove returns the roll needed to move a checker from the provided spaces.
func ValidSpace ¶
Types ¶
type EventBoard ¶
type EventFailedJoin ¶
type EventFailedLeave ¶
type EventFailedOk ¶
type EventFailedRoll ¶
type EventHistory ¶
type EventJoined ¶
type EventList ¶
type EventList struct { Event Games []GameListing }
type EventMoved ¶
type EventNotice ¶
type EventReplay ¶
type EventRolled ¶
type EventSettings ¶
type Game ¶
type Game struct { Started time.Time Ended time.Time Player1 Player Player2 Player Variant int8 // 0 - Backgammon, 1 - Acey-deucey, 2 - Tabula. Board []int8 Turn int8 Roll1 int8 Roll2 int8 Roll3 int8 // Used in tabula games. Moves [][]int8 // Pending moves. Winner int8 Points int8 // Points required to win the match. DoubleValue int8 // Doubling cube value. DoublePlayer int8 // Player that currently posesses the doubling cube. DoubleOffered bool // Whether the current player is offering a double. Reroll bool // Used in acey-deucey. // Fields after this point are provided for backwards-compatibility only and will eventually be removed. Acey bool // For Boxcars v1.2.1 and earlier. // contains filtered or unexported fields }
func (*Game) AddLocalMove ¶
AddLocalMove adds a move without performing any validation. This is useful when adding a move locally while waiting for an EventBoard response from the server.
func (*Game) AddMoves ¶
AddMoves adds moves to the game state. Adding a backwards move will remove the equivalent existing move.
func (*Game) ExpandMove ¶
func (*Game) HaveBearOffDiceRoll ¶
func (*Game) LegalMoves ¶
func (*Game) MayBearOff ¶
MayBearOff returns whether the provided player may bear checkers off of the board.
func (*Game) NextPartialTurn ¶
func (*Game) PartialHandled ¶
func (*Game) PartialTime ¶
func (*Game) PartialTurn ¶
func (*Game) RenderSpace ¶
func (*Game) SetPartialHandled ¶
type GameListing ¶
type GameState ¶
type GameState struct { *Game PlayerNumber int8 Available [][]int8 // Legal moves. Forced bool // A forced move is being played automatically. Spectating bool }
func (*GameState) LocalPlayer ¶
func (*GameState) MayChooseRoll ¶
MayChooseRoll returns whether the player may send the 'ok' command, supplying the chosen roll. This command only applies to acey-deucey games.