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 )
BoardSpaces is the total number of spaces needed to represent a backgammon board.
const BoardSpaces = 28
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)
HomeRange returns the start and end space of the provided player's home board.
func IterateSpaces(from int8, to int8, variant int8, f func(space int8, spaceCount int8))
func NewBoard(variant int8) []int8
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(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
RollForMove returns the roll needed to move a checker from the provided spaces.
func SortMoves(moves [][]int8)
SortMoves sorts moves from highest to lowest.
func SpaceDiff(from int8, to int8, variant int8) int8
func ValidSpace(space int8) bool
type Client interface { HandleReadWrite() Write(message []byte) Terminate(reason string) Terminated() bool }
type Command string
type Event struct { Type string Player string }
type EventBoard struct { Event GameState }
type EventFailedJoin struct { Event Reason string }
type EventFailedLeave struct { Event Reason string }
type EventFailedMove struct { Event From int8 To int8 Reason string }
type EventFailedOk struct { Event Reason string }
type EventFailedRoll struct { Event Reason string }
type EventHelp struct { Event Topic string Message string }
type EventHistory struct { Event Page int Pages int Matches []*HistoryMatch CasualBackgammonSingle int CasualBackgammonMulti int CasualAceyDeuceySingle int CasualAceyDeuceyMulti int CasualTabulaSingle int CasualTabulaMulti int }
type EventJoined struct { Event GameID int PlayerNumber int8 }
type EventLeft struct { Event }
type EventList struct { Event Games []GameListing }
type EventMoved struct { Event Moves [][]int8 }
type EventNotice struct { Event Message string }
type EventPing struct { Event Message string }
type EventReplay struct { Event ID int Content []byte }
type EventRolled struct { Event Roll1 int8 Roll2 int8 Roll3 int8 // Used in tabula games. Selected bool // Whether the roll is selected by the player (used in acey-deucey games). }
type EventSay struct { Event Message string }
type EventSettings struct { Event AutoPlay bool Highlight bool Pips bool Moves bool Flip bool Advanced bool Speed int8 }
type EventType string
type EventWelcome struct { Event PlayerName string Clients int Games int }
type EventWin struct { Event Points int8 }
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 NewGame(variant int8) *Game
func (g *Game) AddLocalMove(move []int8) bool
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 (g *Game) AddMoves(moves [][]int8, local bool) (bool, [][]int8)
AddMoves adds moves to the game state. Adding a backwards move will remove the equivalent existing move.
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
MayBearOff returns whether the provided player may bear checkers off of the board.
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 struct { ID int Password bool Points int8 Players int8 Rating int Name string }
type GameState struct { *Game PlayerNumber int8 Available [][]int8 // Legal moves. Forced bool // A forced move is being played automatically. Spectating bool }
func (g *GameState) LocalPlayer() Player
func (g *GameState) MayChooseRoll() bool
MayChooseRoll returns whether the player may send the 'ok' command, supplying the chosen roll. This command only applies to acey-deucey games.
func (g *GameState) MayDouble() bool
MayDouble returns whether the player may send the 'double' command.
func (g *GameState) MayOK() bool
MayOK returns whether the player may send the 'ok' command.
func (g *GameState) MayReset() bool
MayReset returns whether the player may send the 'reset' command.
func (g *GameState) MayResign() bool
MayResign returns whether the player may send the 'resign' command.
func (g *GameState) MayRoll() bool
MayRoll returns whether the player may send the 'roll' command.
func (g *GameState) OpponentPlayer() Player
func (g *GameState) Pips(player int8) int
Pips returns the pip count for the specified player.
func (g *GameState) SpaceAt(x int8, y int8) int8
type HistoryMatch struct { ID int Timestamp int64 Points int8 Opponent string Winner int8 }
type Player struct { Number int8 // 1 black, 2 white Name string Rating int Points int8 Entered bool // Whether all checkers have entered the board. (Acey-deucey) Inactive int // Inactive time. (Seconds) }
func NewPlayer(number int8) Player
Name | Synopsis |
---|---|
.. | |
cmd | |
bgammon-server | |
pkg | |
server |