engine

package
v0.0.0-...-72ff806 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const AGE_MASK uint64 = 0b1111111111 // age << 54, 10 bits
View Source
const Add int8 = 1
View Source
const CHECKMATE_EVAL int16 = 30000
View Source
const DEFAULT_CACHE_SIZE = 128
View Source
const DEPTH_MASK uint64 = 0b1111111 // depth << 44, 7 bits
View Source
const DarkSquares uint64 = 0xAA55AA55AA55AA55
View Source
const EVAL_MASK uint64 = 0b1111111111111111 // eval << 28, 16 bits
View Source
const EmptyMove = Move(0)
View Source
const MAX_CACHE_SIZE = 120_000
View Source
const MAX_INT = int16(32767)
View Source
const MAX_NON_CHECKMATE float32 = 25000
View Source
const MIN_NON_CHECKMATE float32 = -MAX_NON_CHECKMATE
View Source
const MOVE_MASK uint64 = 0b1111111111111111111111111111 // move << 0, 28 bits
View Source
const MaximumDepth = 128
View Source
const NetInputSize = 769
View Source
const NetLayers = 1
View Source
const NetOutputSize = 1
View Source
const OldAge = uint16(5)
View Source
const Rank2Fill = uint64(1<<A2 | 1<<B2 | 1<<C2 | 1<<D2 | 1<<E2 | 1<<F2 | 1<<G2 | 1<<H2)
View Source
const Rank7Fill = uint64(1<<A7 | 1<<B7 | 1<<C7 | 1<<D7 | 1<<E7 | 1<<F7 | 1<<G7 | 1<<H7)
View Source
const Remove int8 = -1
View Source
const TYPE_MASK uint64 = 0b111 // type << 51, 3 bits

Variables

View Source
var CACHE_ENTRY_SIZE = int(unsafe.Sizeof(CachedEval{}))
View Source
var CurrentHiddenBiases []float32
View Source
var CurrentHiddenWeights []float32
View Source
var CurrentNetworkId uint32
View Source
var CurrentOutputBias float32
View Source
var CurrentOutputWeights []float32
View Source
var DefaultHiddenBiases []float32
View Source
var DefaultHiddenWeights []float32
View Source
var DefaultNetHiddenSize int
View Source
var DefaultNetworkId uint32
View Source
var DefaultOutputBias float32
View Source
var DefaultOutputWeights []float32
View Source
var NameToSquareMap = map[string]Square{
	"a1": A1, "a2": A2, "a3": A3, "a4": A4, "a5": A5, "a6": A6, "a7": A7, "a8": A8,
	"b1": B1, "b2": B2, "b3": B3, "b4": B4, "b5": B5, "b6": B6, "b7": B7, "b8": B8,
	"c1": C1, "c2": C2, "c3": C3, "c4": C4, "c5": C5, "c6": C6, "c7": C7, "c8": C8,
	"d1": D1, "d2": D2, "d3": D3, "d4": D4, "d5": D5, "d6": D6, "d7": D7, "d8": D8,
	"e1": E1, "e2": E2, "e3": E3, "e4": E4, "e5": E5, "e6": E6, "e7": E7, "e8": E8,
	"f1": F1, "f2": F2, "f3": F3, "f4": F4, "f5": F5, "f6": F6, "f7": F7, "f8": F8,
	"g1": G1, "g2": G2, "g3": G3, "g4": G4, "g5": G5, "g6": G6, "g7": G7, "g8": G8,
	"h1": H1, "h2": H2, "h3": H3, "h4": H4, "h5": H5, "h6": H6, "h7": H7, "h8": H8,
}
View Source
var NetHiddenSize = 128
View Source
var Skills1HiddenBiases []float32
View Source
var Skills1HiddenWeights []float32
View Source
var Skills1NetHiddenSize int
View Source
var Skills1NetworkId uint32
View Source
var Skills1OutputBias float32
View Source
var Skills1OutputWeights []float32
View Source
var Skills2HiddenBiases []float32
View Source
var Skills2HiddenWeights []float32
View Source
var Skills2NetHiddenSize int
View Source
var Skills2NetworkId uint32
View Source
var Skills2OutputBias float32
View Source
var Skills2OutputWeights []float32
View Source
var Skills3HiddenBiases []float32
View Source
var Skills3HiddenWeights []float32
View Source
var Skills3NetHiddenSize int
View Source
var Skills3NetworkId uint32
View Source
var Skills3OutputBias float32
View Source
var Skills3OutputWeights []float32
View Source
var Skills4HiddenBiases []float32
View Source
var Skills4HiddenWeights []float32
View Source
var Skills4NetHiddenSize int
View Source
var Skills4NetworkId uint32
View Source
var Skills4OutputBias float32
View Source
var Skills4OutputWeights []float32
View Source
var Skills5HiddenBiases []float32
View Source
var Skills5HiddenWeights []float32
View Source
var Skills5NetHiddenSize int
View Source
var Skills5NetworkId uint32
View Source
var Skills5OutputBias float32
View Source
var Skills5OutputWeights []float32
View Source
var Skills6HiddenBiases []float32
View Source
var Skills6HiddenWeights []float32
View Source
var Skills6NetHiddenSize int
View Source
var Skills6NetworkId uint32
View Source
var Skills6OutputBias float32
View Source
var Skills6OutputWeights []float32
View Source
var SquareMask = initSquareMask()
View Source
var TranspositionTable = NewCache(DEFAULT_CACHE_SIZE)

Functions

func LoadNetwork

func LoadNetwork(path string) error

load a neural network from file

func Pack

func Pack(hashmove Move, eval int16, depth int8, nodeType NodeType, age uint16) uint64

func ReLu

func ReLu(x float32) float32

func RoundPowerOfTwo

func RoundPowerOfTwo(size int) int

func Unpack

func Unpack(data uint64) (hashmove Move, eval int16, depth int8, nodeType NodeType, age uint16)

Types

type Bitboard

type Bitboard struct {
	// contains filtered or unexported fields
}

func StartingBoard

func StartingBoard() Bitboard

func (*Bitboard) AllPieces

func (b *Bitboard) AllPieces() map[Square]Piece

func (*Bitboard) Bishops

func (b *Bitboard) Bishops() uint64

func (*Bitboard) Clear

func (b *Bitboard) Clear(square Square, piece Piece)

func (*Bitboard) Draw

func (b *Bitboard) Draw() string

Draw returns visual representation of the board useful for debugging.

func (*Bitboard) Fen

func (b *Bitboard) Fen() string

func (*Bitboard) GetBitboardOf

func (b *Bitboard) GetBitboardOf(piece Piece) uint64

func (*Bitboard) GetBlackPieces

func (b *Bitboard) GetBlackPieces() uint64

func (*Bitboard) GetWhitePieces

func (b *Bitboard) GetWhitePieces() uint64

func (*Bitboard) HasThreats

func (b *Bitboard) HasThreats(color Color) bool

func (*Bitboard) IsEndGame

func (b *Bitboard) IsEndGame(turn Color) bool

func (*Bitboard) Kings

func (b *Bitboard) Kings() uint64

func (*Bitboard) Knights

func (b *Bitboard) Knights() uint64

func (*Bitboard) Move

func (b *Bitboard) Move(src Square, dest Square, sourcePiece Piece, destinationPiece Piece)

func (*Bitboard) Pawns

func (b *Bitboard) Pawns() uint64

func (*Bitboard) PieceAt

func (b *Bitboard) PieceAt(sq Square) Piece

func (*Bitboard) Queens

func (b *Bitboard) Queens() uint64

func (*Bitboard) Rooks

func (b *Bitboard) Rooks() uint64

func (*Bitboard) SeeGe

func (b *Bitboard) SeeGe(toSq Square, target Piece, frSq Square, aPiece Piece, bound int16) int16

func (*Bitboard) StaticExchangeEval

func (b *Bitboard) StaticExchangeEval(toSq Square, target Piece, frSq Square, aPiece Piece) int16

func (*Bitboard) UpdateSquare

func (b *Bitboard) UpdateSquare(sq Square, newPiece Piece, oldPiece Piece)

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache(megabytes int) *Cache

func (*Cache) AdvanceAge

func (c *Cache) AdvanceAge()

func (*Cache) Consumed

func (c *Cache) Consumed() int

func (*Cache) Get

func (c *Cache) Get(hash uint64) (Move, int16, int8, NodeType, bool)

func (*Cache) Prefetch

func (c *Cache) Prefetch(hash uint64)

func (*Cache) Set

func (c *Cache) Set(hash uint64, hashmove Move, eval int16, depth int8, nodeType NodeType)

func (*Cache) Size

func (c *Cache) Size() int

type CachedEval

type CachedEval struct {
	Key  uint64 // 8
	Data uint64 // 8
}

func (*CachedEval) Update

func (c *CachedEval) Update(key uint64, data uint64)

type Color

type Color int8
const (
	NoColor Color = iota - 1
	Black
	White
)

func (Color) Other

func (c Color) Other() Color

type Direction

type Direction uint8
const (
	North Direction = iota
	NorthEast
	East
	SouthEast
	South
	SouthWest
	West
	NorthWest
)

type File

type File int8
const (
	FileA File = iota
	FileB
	FileC
	FileD
	FileE
	FileF
	FileG
	FileH
)

func (File) Name

func (f File) Name() string

type Game

type Game struct {
	// contains filtered or unexported fields
}

func FromFen

func FromFen(fen string) Game

func NewGame

func NewGame(
	position *Position,
	moves []Move,
	numberOfMoves uint16) Game

func (*Game) Fen

func (g *Game) Fen() string

func (*Game) Move

func (g *Game) Move(m Move)

func (*Game) MoveClock

func (g *Game) MoveClock() uint16

func (*Game) ParseGameMoves

func (g *Game) ParseGameMoves(moveStr []string)

func (*Game) Position

func (g *Game) Position() *Position

type Move

type Move uint32

func NewMove

func NewMove(from Square, to Square, movingPiece Piece, capturedPiece Piece, promoType PieceType, tag MoveTag) Move

func (Move) CapturedPiece

func (m Move) CapturedPiece() Piece

func (Move) Destination

func (m Move) Destination() Square

func (Move) IsCapture

func (m Move) IsCapture() bool

func (Move) IsCastle

func (m Move) IsCastle() bool

func (Move) IsEnPassant

func (m Move) IsEnPassant() bool

func (Move) IsKingSideCastle

func (m Move) IsKingSideCastle() bool

func (Move) IsQueenSideCastle

func (m Move) IsQueenSideCastle() bool

func (Move) MovingPiece

func (m Move) MovingPiece() Piece

func (Move) PromoType

func (m Move) PromoType() PieceType

func (Move) Source

func (m Move) Source() Square

func (Move) Tag

func (m Move) Tag() MoveTag

func (Move) ToString

func (m Move) ToString() string

type MoveList

type MoveList struct {
	Moves    []Move
	Scores   []int32
	IsScored bool
	Size     int
	Next     int
}

func NewMoveList

func NewMoveList(capacity int) MoveList

func (*MoveList) Add

func (ml *MoveList) Add(m Move)

func (*MoveList) AddFour

func (ml *MoveList) AddFour(m1, m2, m3, m4 Move)

func (*MoveList) IncNext

func (ml *MoveList) IncNext()

func (*MoveList) IsEmpty

func (ml *MoveList) IsEmpty() bool

func (*MoveList) Swap

func (ml *MoveList) Swap(first int, second int)

func (*MoveList) SwapWith

func (ml *MoveList) SwapWith(best int)

type MoveTag

type MoveTag uint8
const (
	// KingSideCastle indicates that the move is a king side castle.
	KingSideCastle MoveTag = 1 << iota
	// QueenSideCastle indicates that the move is a queen side castle.
	QueenSideCastle
	// Capture indicates that the move captures a piece.
	Capture
	// EnPassant indicates that the move captures via en passant.
	EnPassant
)

type NetworkState

type NetworkState struct {
	HiddenOutputs     [][]float32
	EmptyHiddenOutput []float32
	CurrentHidden     int
	HiddenWeights     []float32
	HiddenBiases      []float32
	OutputWeights     []float32
	OutputBias        float32
}

func NewNetworkState

func NewNetworkState() NetworkState

func (*NetworkState) QuickFeed

func (n *NetworkState) QuickFeed() float32

func (*NetworkState) Recalculate

func (n *NetworkState) Recalculate(input []int16)

func (*NetworkState) RevertHidden

func (n *NetworkState) RevertHidden()

func (*NetworkState) UpdateHidden

func (n *NetworkState) UpdateHidden(updates *Updates)

type NodeType

type NodeType uint8
const (
	Exact      NodeType = 1 << iota // PV-Node
	UpperBound                      // All-Node
	LowerBound                      // Cut-Node
)

type Piece

type Piece int8
const (
	NoPiece Piece = iota
	WhitePawn
	WhiteKnight
	WhiteBishop
	WhiteRook
	WhiteQueen
	WhiteKing
	BlackPawn
	BlackKnight
	BlackBishop
	BlackRook
	BlackQueen
	BlackKing
)

func GetPiece

func GetPiece(pieceType PieceType, color Color) Piece

func (Piece) Color

func (p Piece) Color() Color

func (Piece) Name

func (p Piece) Name() string

func (Piece) Type

func (p Piece) Type() PieceType

func (Piece) Weight

func (p Piece) Weight() int16

type PieceType

type PieceType int8
const (
	NoType PieceType = iota
	Pawn
	Knight
	Bishop
	Rook
	Queen
	King
)

func (PieceType) Name

func (t PieceType) Name() string

type Position

type Position struct {
	Board     Bitboard
	Net       NetworkState
	Updates   Updates
	EnPassant Square
	Tag       PositionTag

	Positions     map[uint64]int
	HalfMoveClock uint8
	// contains filtered or unexported fields
}

func (*Position) ClearTag

func (p *Position) ClearTag(tag PositionTag)

func (*Position) Copy

func (p *Position) Copy() *Position

func (*Position) Evaluate

func (p *Position) Evaluate() int16

func (*Position) Fen

func (p *Position) Fen() string

func (*Position) GameMakeMove

func (p *Position) GameMakeMove(move Move) (Square, PositionTag, uint8, bool)

func (*Position) GameUnMakeMove

func (p *Position) GameUnMakeMove(move Move, tag PositionTag, enPassant Square, halfClock uint8)

func (*Position) GetCaptureMoves

func (p *Position) GetCaptureMoves(ml *MoveList)

func (*Position) GetQuietMoves

func (p *Position) GetQuietMoves(ml *MoveList)

func (*Position) HasCastling

func (p *Position) HasCastling() bool

func (*Position) HasTag

func (p *Position) HasTag(tag PositionTag) bool

func (*Position) Hash

func (p *Position) Hash() uint64

func (*Position) IsDraw

func (p *Position) IsDraw() bool

func (*Position) IsEndGame

func (p *Position) IsEndGame() bool

func (*Position) IsFIDEDrawRule

func (p *Position) IsFIDEDrawRule() bool

func (*Position) IsInCheck

func (p *Position) IsInCheck() bool

func (*Position) IsPseudoLegal

func (p *Position) IsPseudoLegal(move Move) bool

func (*Position) MakeMove

func (p *Position) MakeMove(move Move) (Square, PositionTag, uint8, bool)

func (*Position) MakeNullMove

func (p *Position) MakeNullMove() Square

func (*Position) MoveToPGN

func (p *Position) MoveToPGN(move Move) string

func (*Position) NetInput

func (p *Position) NetInput() []int16

func (*Position) ParseSearchMoves

func (p *Position) ParseSearchMoves(moveStr []string) []Move

func (*Position) PseudoLegalMoves

func (p *Position) PseudoLegalMoves() []Move

func (*Position) SetTag

func (p *Position) SetTag(tag PositionTag)

func (*Position) ToggleTag

func (p *Position) ToggleTag(tag PositionTag)

func (*Position) ToggleTurn

func (p *Position) ToggleTurn()

func (*Position) Turn

func (p *Position) Turn() Color

func (*Position) UnMakeMove

func (p *Position) UnMakeMove(move Move, tag PositionTag, enPassant Square, halfClock uint8)

func (*Position) UnMakeNullMove

func (p *Position) UnMakeNullMove(ep Square)

type PositionTag

type PositionTag uint8
const (
	WhiteCanCastleKingSide PositionTag = 1 << iota
	WhiteCanCastleQueenSide
	BlackCanCastleKingSide
	BlackCanCastleQueenSide
	InCheck
	BlackToMove
	WhiteToMove
)

type Rank

type Rank int8
const (
	Rank1 Rank = iota
	Rank2
	Rank3
	Rank4
	Rank5
	Rank6
	Rank7
	Rank8
)

func (Rank) Name

func (r Rank) Name() int

type Square

type Square int8
const (
	NoSquare Square = iota - 1
	A1
	B1
	C1
	D1
	E1
	F1
	G1
	H1
	A2
	B2
	C2
	D2
	E2
	F2
	G2
	H2
	A3
	B3
	C3
	D3
	E3
	F3
	G3
	H3
	A4
	B4
	C4
	D4
	E4
	F4
	G4
	H4
	A5
	B5
	C5
	D5
	E5
	F5
	G5
	H5
	A6
	B6
	C6
	D6
	E6
	F6
	G6
	H6
	A7
	B7
	C7
	D7
	E7
	F7
	G7
	H7
	A8
	B8
	C8
	D8
	E8
	F8
	G8
	H8
)

func SquareOf

func SquareOf(file File, rank Rank) Square

func (Square) File

func (sq Square) File() File

func (Square) GetColor

func (sq Square) GetColor() Color

func (Square) Name

func (s Square) Name() string

func (Square) Rank

func (sq Square) Rank() Rank

func (Square) String

func (sq Square) String() string

type Status

type Status uint8
const (
	Checkmate Status = iota
	Draw
	Unknown
)

type Updates

type Updates struct {
	Indices []int16
	Coeffs  []int8
	Size    int
}

func (*Updates) Add

func (u *Updates) Add(index int16, coeff int8)

Jump to

Keyboard shortcuts

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