Version: v0.0.0-...-3b02af1 Latest Latest

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

Go to latest
Published: Jul 31, 2018 License: MIT Imports: 11 Imported by: 0




View Source
const (
	BoardSize       = 8
	BoardCellsCount = BoardSize * BoardSize


View Source
var EmptyAddress = Address{-127, -127}
View Source
var ErrAlreadyOccupied = errors.New("cell already occupied")
View Source
var ErrNotOccupied = errors.New("cell is not occupied")
View Source
var ErrNotValidMove = errors.New("not valid move")
View Source
var ErrNotValidTranscript = errors.New("not valid transcript")
View Source
var OthelloBoard = Board{
	Last:   Address{4, 4},
	Blacks: (1 << (3*8 + 4)) | (1 << (4*8 + 3)),
	Whites: (1 << (3*8 + 3)) | (1 << (4*8 + 4)),


func DecodeIntFromBase64

func DecodeIntFromBase64(s string) (int64, error)

func DecodeStringToInt

func DecodeStringToInt(s string) (int64, error)

func EncodeIntToBase64

func EncodeIntToBase64(v int64) string

func EncodeIntToString

func EncodeIntToString(v int64) string

func VerifyBoardTranscript

func VerifyBoardTranscript(b Board, t Transcript) error


type Address

type Address struct {
	X, Y int8

func CellAddressToRevAddress

func CellAddressToRevAddress(ca turnbased.CellAddress) Address

func (Address) Index

func (a Address) Index() int8

func (Address) IsOnBoard

func (a Address) IsOnBoard() bool

func (Address) String

func (a Address) String() string

func (Address) ToCellAddress

func (a Address) ToCellAddress() turnbased.CellAddress

func (Address) ToMove

func (a Address) ToMove() Move

type Board

type Board struct {
	Blacks Disks
	Whites Disks
	Last   Address

func NewBoardFromBase64

func NewBoardFromBase64(s string) (board Board, err error)

func NewBoardFromBytes

func NewBoardFromBytes(b []byte) (board Board)

func Replay

func Replay(board Board, transcript Transcript, backSteps int) Board

func (Board) DisksCount

func (b Board) DisksCount() int

func (Board) DrawBoard

func (b Board) DrawBoard(black, white, possibleMove string, colSeparator, rowSeparator string) string

func (Board) DrawBoardAsEmoji

func (b Board) DrawBoardAsEmoji(black, white, possibleMove string) string

func (Board) DrawBoardAsText

func (b Board) DrawBoardAsText(possibleMove string) string

func (Board) IsCompleted

func (b Board) IsCompleted() bool

func (Board) IsEmpty

func (b Board) IsEmpty() bool

func (Board) MakeMove

func (b Board) MakeMove(player Disk, a Address) (board Board, err error)

func (Board) NextPlayer

func (b Board) NextPlayer() Disk

func (Board) Rows

func (b Board) Rows(black, white, possibleMove, empty string) (rows [8][8]string)

func (Board) Score

func (b Board) Score(player Disk) int

func (Board) Scores

func (b Board) Scores() (black, white int)

func (Board) ToBase64

func (b Board) ToBase64() string

func (Board) ToBytes

func (b Board) ToBytes() []byte

func (Board) Turns

func (b Board) Turns() int

func (Board) UndoMove

func (b Board) UndoMove(a, prevMove Address) (board Board)

type Disk

type Disk rune
var (
	Black     Disk = 'b'
	White     Disk = 'w'
	Empty     Disk = ' '
	Completed Disk = '!'

func OtherPlayer

func OtherPlayer(player Disk) Disk

type Disks

type Disks int64

type Mode

type Mode string
const (
	SinglePlayer Mode = "s"
	// WithAI Mode = "ai"
	MultiPlayer = "m"

type Move

type Move byte

func (Move) Address

func (m Move) Address() Address

type SimpleAI

type SimpleAI struct {

func (SimpleAI) GetMove

func (SimpleAI) GetMove(board Board, player Disk) (move Address)

type Transcript

type Transcript []byte

func AddMove

func AddMove(transcript Transcript, backSteps int, a Address) (Transcript, int)

func EmptyTranscript

func EmptyTranscript() Transcript

func NewTranscript

func NewTranscript(s string) (transcript Transcript)

func NewTranscriptFromHumanReadable

func NewTranscriptFromHumanReadable(s string) (transcript Transcript)

func (Transcript) Equal

func (t Transcript) Equal(t2 Transcript) bool

func (Transcript) LastMove

func (t Transcript) LastMove() Move

func (Transcript) NextMove

func (t Transcript) NextMove() (Move, Transcript)

func (Transcript) Pop

func (t Transcript) Pop() (Move, Transcript)

func (Transcript) String

func (t Transcript) String() string

func (Transcript) ToBase64

func (t Transcript) ToBase64() string

Jump to

Keyboard shortcuts

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