Documentation
¶
Overview ¶
Package bgammon provides an interface for connecting to the bgammon.org online backgammon server.
Index ¶
- Constants
- Variables
- 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 EventFailedCreate
- type EventFailedJoin
- type EventFailedLeave
- type EventFailedMove
- type EventFailedOk
- type EventFailedRoll
- 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) LastActive() time.Time
- 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)
- func (g *Game) UpdateLastActive()
- type GameListing
- type GameState
- func (g *GameState) LocalPlayer() Player
- func (g *GameState) MayChooseRoll() bool
- func (g *GameState) MayDecline() bool
- func (g *GameState) MayDouble() bool
- func (g *GameState) MayOK() bool
- func (g *GameState) MayReset() 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" // Offer (or accept) a rematch after a match has been finished. CommandFollow = "follow" // Follow a player. CommandUnfollow = "unfollow" // Un-follow a player. CommandBoard = "board" // Print current board state in human-readable form. CommandPong = "pong" // Response to server ping. CommandDisconnect = "disconnect" // Disconnect from server. CommandMOTD = "motd" // Read (or write) the message of the day. CommandBroadcast = "broadcast" // Send a message to all players. CommandDefcon = "defcon" // Apply restrictions to guests to prevent abuse. CommandKick = "kick" // Kick a user from the server. CommandBan = "ban" // Ban an IP address or account. CommandUnban = "unban" // Unban an IP address or account. CommandShutdown = "shutdown" // Prevent the creation of new matches. )
const ( EventTypeWelcome = "welcome" EventTypeHelp = "help" EventTypePing = "ping" EventTypeNotice = "notice" EventTypeSay = "say" EventTypeList = "list" EventTypeFailedCreate = "failedcreate" 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 ¶
var HelpText = map[string]string{ CommandLogin: "[username] [password] - Log in. A random username is assigned when none is provided.", CommandRegister: "<email> <username> <password> - Register an account. A valid email address must be provided.", CommandResetPassword: "<email> - Request a password reset link via email.", CommandPassword: "<old> <new> - Change account password.", CommandSet: "<name> <value> - Change account setting. Available settings: highlight, pips and moves.", CommandReplay: "<id> - Retrieve replay of the specified game.", CommandHistory: "<username> [page] - Retrieve match history of the specified player.", CommandHelp: "[command] - Request help for all commands, or optionally a specific command.", CommandSay: "<message> - Send a chat message. This command can only be used after creating or joining a match.", CommandList: "- List all matches.", CommandCreate: "<public>/<private [password]> <points> <variant> [name] - Create a match. A variant value of 0 represents a standard game, a value of 1 represents an acey-deucey game and a value of 2 represents a tabula game.", CommandJoin: "<id>/<username> [password] - Join match by match ID or by player.", CommandLeave: "- Leave match.", CommandDouble: "- Offer double to opponent.", CommandResign: "- Resign game. Resigning when a double is offered will decline the offer.", CommandRoll: "- Roll dice.", CommandMove: "<from-to> [from-to]... - Move checkers.", CommandReset: "- Reset pending checker movement.", CommandOk: "[1-6] - Accept double offer or confirm checker movement. The parameter for this command only applies in acey-deucey games.", CommandRematch: "- Request (or accept) a rematch after a match has been finished.", CommandFollow: "<username> - Follow a player. A notification is shown whenever a followed player goes online or offline.", CommandUnfollow: "<username> - Un-follow a player.", CommandBoard: "- Request current match state.", CommandPong: "<message> - Sent in response to server ping event to prevent the connection from timing out.", CommandDisconnect: "- Disconnect from the server.", CommandMOTD: "[message] - View (or set) message of the day. Specifying a new message of the day is only available to server administrators.", CommandBroadcast: "<message> - Send a message to all players. This command is only available to server administrators.", CommandDefcon: "[level] - Apply restrictions to guests to prevent abuse. Levels:\n1. Disallow new accounts from being registered.\n2. Only registered users may connect.\n3. Only registered users may chat and set custom match titles.\n4. Warning message is broadcast to all users.\n5. Normal operation.", CommandKick: "<username> [reason] - Kick a user from the server.", CommandBan: "<username> [reason] - Ban a user by IP addresss and account (if logged in).", CommandUnban: "<IP>/<username> - Unban a user by IP address or account.", CommandShutdown: "<minutes> <reason> - Prevent the creation of new matches and periodically warn players about the server shutting down. This command is only available to server administrators.", }
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 EventFailedCreate ¶
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 int64 Ended int64 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) LastActive ¶
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 ¶
func (*Game) UpdateLastActive ¶
func (g *Game) UpdateLastActive()
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.
func (*GameState) MayDecline ¶
MayDecline returns whether the player may send the 'resign' command to decline a double offer.