fibs

package module
v0.0.0-...-18c4cdb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2021 License: GPL-3.0 Imports: 17 Imported by: 2

README

fibs

GoDoc Donate

FIBS (online backgammon) client library

Features

  • Client provides methods for connecting to FIBS and manages interactions
  • Board provides methods for retrieving the current game state and playing the game
  • Watch backgammon TV (spectate live matches continuously)

Applications

  • Boxcars, a FIBS client with a graphical user interface
  • bgammon, a FIBS client with a terminal user interface

Documentation

Documentation is available via godoc.

Support

Please share issues and suggestions here.

Documentation

Overview

Package fibs provides a FIBS.com (online backgammon) client library.

In addition to the standard FIBS commands, the following internal custom commands are available:

- `watch` - Watch a random game - `tv` - Watch random games continuously

Index

Constants

View Source
const (
	StateLength = iota
	StatePlayerScore
	StateOpponentScore
	StateBoardSpace0
)
View Source
const (
	StatePlayerName = iota
	StateOpponentName
)
View Source
const (
	StateTurn = 29 + iota
	StatePlayerDice1
	StatePlayerDice2
	StateOpponentDice1
	StateOpponentDice2
	StateDoublingValue
	StatePlayerMayDouble
	StateOpponentMayDouble
	StateWasDoubled
	StatePlayerColor
	StateDirection
	StateObsoleteHome
	StateObsoleteBar
	StatePlayerHome
	StateOpponentHome
	StatePlayerBar
	StateOpponentBar
	StateMovablePieces
	StateObsoletePlayerForced
	StateObsoleteOpponentForced
	StateRedoubles
)
View Source
const (
	BoxDrawingsLightVertical = '|'
)
View Source
const (
	SpaceUnknown = -1
)

Variables

View Source
var (
	TypeWelcome      = []byte("1")
	TypeOwnInfo      = []byte("2")
	TypeMOTD         = []byte("3")
	TypeEndMOTD      = []byte("4")
	TypeWhoInfo      = []byte("5")
	TypeEndWhoInfo   = []byte("6")
	TypeLogin        = []byte("7")
	TypeLogout       = []byte("8")
	TypeMsg          = []byte("9")
	TypeMsgDelivered = []byte("10")
	TypeMsgSaved     = []byte("11")
	TypeSay          = []byte("12")
	TypeShout        = []byte("13")
	TypeWhisper      = []byte("14")
	TypeKibitz       = []byte("15")
	TypeYouSay       = []byte("16")
	TypeYouShout     = []byte("17")
	TypeYouWhisper   = []byte("18")
	TypeYouKibitz    = []byte("19")
	TypeBoardState   = []byte("board:")
)
View Source
var (
	StatusWriter io.Writer
	GameWriter   io.Writer
)
View Source
var Debug = 0

Debug controls the level of debug information to print.

View Source
var DefaultProxyAddress = ""

Functions

This section is empty.

Types

type Board

type Board struct {
	Premovefrom map[int]int
	Premoveto   map[int]int

	sync.Mutex
	// contains filtered or unexported fields
}

func NewBoard

func NewBoard(client *Client) *Board

func (*Board) AddPreMove

func (b *Board) AddPreMove(from int, to int) bool

func (*Board) Draw

func (b *Board) Draw()

func (*Board) GetIntState

func (b *Board) GetIntState() []int

func (*Board) GetPreMoves

func (b *Board) GetPreMoves() [][2]int

func (*Board) GetSelection

func (b *Board) GetSelection() (num int, space int)

func (*Board) GetState

func (b *Board) GetState() string

func (*Board) GetStringState

func (b *Board) GetStringState() []string

TODO refactor

func (*Board) GetValidMoves

func (b *Board) GetValidMoves(from int) [][]int

func (*Board) Move

func (b *Board) Move(player int, f string, t string)

func (*Board) PlayerBarSpace

func (b *Board) PlayerBarSpace() int

func (*Board) PlayerBearOffSpace

func (b *Board) PlayerBearOffSpace() int

func (*Board) PlayerHomeSpaces

func (b *Board) PlayerHomeSpaces() (int, int)

func (*Board) PlayerPieceAreHome

func (b *Board) PlayerPieceAreHome() bool

func (*Board) Render

func (b *Board) Render() []byte

func (*Board) ResetMoves

func (b *Board) ResetMoves()

func (*Board) ResetPreMoves

func (b *Board) ResetPreMoves()

func (*Board) ResetSelection

func (b *Board) ResetSelection()

func (*Board) SetSelection

func (b *Board) SetSelection(num int, space int)

func (*Board) SetState

func (b *Board) SetState(state string)

func (*Board) SimplifyMoves

func (b *Board) SimplifyMoves()

func (*Board) ValidMove

func (b *Board) ValidMove(f int, t int) bool

type Client

type Client struct {
	In    chan []byte
	Out   chan []byte
	Event chan interface{}

	Username string
	Password string

	Board *Board
	// contains filtered or unexported fields
}

func NewClient

func NewClient(serverAddress string, username string, password string) *Client

func (*Client) CallTELNET

func (c *Client) CallTELNET(ctx telnet.Context, w telnet.Writer, r telnet.Reader)

CallTELNET is called when a connection is made with the server.

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) GetAllWhoInfo

func (c *Client) GetAllWhoInfo() []*WhoInfo

func (*Client) LoggedIn

func (c *Client) LoggedIn() bool

func (*Client) WatchRandomGame

func (c *Client) WatchRandomGame()

type EventBoardState

type EventBoardState struct {
	S []string
	V []int
}

type EventDraw

type EventDraw struct{}

type EventMessage

type EventMessage struct {
	Message string
}

type EventMove

type EventMove struct {
	Player int
	From   int
	To     int
}

type EventWho

type EventWho struct {
	Who []*WhoInfo
}

type WhoInfo

type WhoInfo struct {
	Username   string
	Opponent   string
	Watching   string
	Ready      bool
	Away       bool
	Rating     int
	Experience int
	Idle       int
	LoginTime  int
	ClientName string
}

func (*WhoInfo) String

func (w *WhoInfo) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL