tak

package
v0.0.0-...-7af1aca Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 5 Imported by: 12

Documentation

Index

Constants

View Source
const (
	White   Color = 1 << 7
	Black   Color = 1 << 6
	NoColor Color = 0

	Flat     Kind = 1
	Standing Kind = 2
	Capstone Kind = 3
)

Variables

View Source
var (
	ErrOccupied       = errors.New("position is occupied")
	ErrIllegalSlide   = errors.New("illegal slide")
	ErrNoCapstone     = errors.New("capstone has already been played")
	ErrIllegalOpening = errors.New("illegal opening move")
)

Functions

This section is empty.

Types

type Analysis

type Analysis struct {
	WhiteGroups []uint64
	BlackGroups []uint64
}

type Color

type Color byte

func (Color) Flip

func (c Color) Flip() Color

func (Color) String

func (c Color) String() string

type Config

type Config struct {
	Size      int
	Pieces    int
	Capstones int

	BlackWinsTies bool
	// contains filtered or unexported fields
}

type Kind

type Kind byte

type Move

type Move struct {
	X, Y   int8
	Type   MoveType
	Slides Slides
}

func (Move) Dest

func (m Move) Dest() (int8, int8)

func (Move) Equal

func (m Move) Equal(rhs Move) bool

func (Move) IsSlide

func (m Move) IsSlide() bool

type MoveType

type MoveType byte
const (
	Pass MoveType = 1 + iota
	PlaceFlat
	PlaceStanding
	PlaceCapstone
	SlideLeft
	SlideRight
	SlideUp
	SlideDown
)
const TypeMask MoveType = 0xf

func (MoveType) String

func (i MoveType) String() string

type Piece

type Piece byte

func MakePiece

func MakePiece(color Color, kind Kind) Piece

func (Piece) Color

func (p Piece) Color() Color

func (Piece) IsRoad

func (p Piece) IsRoad() bool

func (Piece) Kind

func (p Piece) Kind() Kind

func (Piece) String

func (p Piece) String() string

type Position

type Position struct {
	White    uint64
	Black    uint64
	Standing uint64
	Caps     uint64
	Height   []uint8
	Stacks   []uint64
	// contains filtered or unexported fields
}

func Alloc

func Alloc(size int) *Position

func FromSquares

func FromSquares(cfg Config, board [][]Square, move int) (*Position, error)

FromSquares initializes a Position with the specified squares and move number. `board` is a slice of rows, numbered from low to high, each of which is a slice of positions.

func New

func New(g Config) *Position

func (*Position) AllMoves

func (p *Position) AllMoves(moves []Move) []Move

func (*Position) Analysis

func (p *Position) Analysis() *Analysis

func (*Position) At

func (p *Position) At(x, y int) Square

func (*Position) BlackStones

func (p *Position) BlackStones() int

func (*Position) Clone

func (p *Position) Clone() *Position

func (*Position) Config

func (p *Position) Config() Config

func (*Position) Equal

func (p *Position) Equal(rhs *Position) bool

func (*Position) GameOver

func (p *Position) GameOver() (over bool, winner Color)

func (*Position) Hash

func (p *Position) Hash() uint64

func (*Position) Move

func (p *Position) Move(m Move) (*Position, error)

func (*Position) MoveNumber

func (p *Position) MoveNumber() int

func (*Position) MovePreallocated

func (p *Position) MovePreallocated(m Move, next *Position) (*Position, error)

func (*Position) Size

func (p *Position) Size() int

func (*Position) ToMove

func (p *Position) ToMove() Color

func (*Position) Top

func (p *Position) Top(x, y int) Piece

func (*Position) WhiteStones

func (p *Position) WhiteStones() int

func (*Position) WinDetails

func (p *Position) WinDetails() WinDetails

type SlideIterator

type SlideIterator uint32

func (SlideIterator) Elem

func (s SlideIterator) Elem() int

func (SlideIterator) Next

func (s SlideIterator) Next() SlideIterator

func (SlideIterator) Ok

func (s SlideIterator) Ok() bool

type Slides

type Slides uint32

Slides is essentially a packed [8]uint4, used to represent the slide counts in a Tak move in a space-efficient way. We store the first drop count in (s&0xf), the next in (s&0xf0), and so on.

func MkSlides

func MkSlides(drops ...int) Slides

func (Slides) Empty

func (s Slides) Empty() bool

func (Slides) First

func (s Slides) First() int

func (Slides) Iterator

func (s Slides) Iterator() SlideIterator

func (Slides) Len

func (s Slides) Len() int

func (Slides) Prepend

func (s Slides) Prepend(next int) Slides

func (Slides) Singleton

func (s Slides) Singleton() bool

type Square

type Square []Piece

type WinDetails

type WinDetails struct {
	Over       bool
	Reason     WinReason
	Winner     Color
	WhiteFlats int
	BlackFlats int
}

type WinReason

type WinReason int
const (
	RoadWin WinReason = iota
	FlatsWin
	Resignation
)

Jump to

Keyboard shortcuts

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