board

package
v1.0.2-beta Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HFNONE NONE flag for hash table
	HFNONE = iota
	// HFALPHA Alpha flag for hash table
	HFALPHA
	// HFBETA Beta flag for hash table
	HFBETA
	// HFEXACT Exact flag for hash table
	HFEXACT
)
View Source
const Infinite = 30000

Infinite Largest score value

View Source
const IsMate = Infinite - MaxDepth
View Source
const MaxDepth = 64

MaxDepth The max depth the engine will try to search to

View Source
const NoMove = 0

NoMove constant for no move found

View Source
const SquareNumber = 120

SquareNumber Number of squares in the board representastion

View Source
const StartPosFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 0"

StartPosFEN The fen string for a starting position

Variables

View Source
var DEBUG bool = false //Default set to true while debugging, should be false normally

DEBUG tells us if we should output debug messages

View Source
var MoveFlagCA = 0x1000000

MoveFlagCA Castel flag

View Source
var MoveFlagCAP = 0x7C000

MoveFlagCAP Capture flag

View Source
var MoveFlagEP = 0x40000

MoveFlagEP EnPas flag

View Source
var MoveFlagPROM = 0xF00000

MoveFlagPROM Promotion flag

View Source
var MoveFlagPS = 0x80000

MoveFlagPS Pawn Start flag

Functions

func GetCapture

func GetCapture(move int) int

GetCapture get capture value from move int

func GetFrom

func GetFrom(move int) int

GetFrom value from move int

func GetPieceValue

func GetPieceValue(piece int) int

GetPieceValue returns the value of a piece

func GetPromoted

func GetPromoted(move int) int

GetPromoted Get promote value from move int

func GetTo

func GetTo(move int) int

GetTo get TO value from move int

func InitMvvLva

func InitMvvLva()

InitMvvLva MvvLva (Most valuable victim least valuable attacker)

func Initialize

func Initialize()

Initialize conversion arrays for engine operation

func MoveToString

func MoveToString(move int) string

MoveToString move int to algebraic notation

func SquareToString

func SquareToString(sq int) string

SquareToString square to algebraic notation

func ToMove

func ToMove(from, to, capture, promotion, flag int) int

ToMove Puts all move info into a single move int

Types

type HashEnteryStruct

type HashEnteryStruct struct {
	PosKey uint64
	Move   int
	Score  int
	Depth  int
	Flags  int
}

PVEnteryStruct The struct for each entry in the PV table

type HashTableStruct

type HashTableStruct struct {
	Entries     []HashEnteryStruct
	EntrieCount uint64
	NewWrite    int
	OverWrite   int
	Hit         int
	Cut         int
}

PVTableStruct Struct to hole the PVTable

func (*HashTableStruct) Clear

func (table *HashTableStruct) Clear()

Clear Clear the PV table

func (*HashTableStruct) Init

func (table *HashTableStruct) Init(hashSizeMB uint64)

initPVTables Initilize our PV Table slice with a exact amount of memory based on hashSizeMB

type MoveListStruct

type MoveListStruct struct {
	Moves [maxPositionMoves]MoveStruct
	Count int
}

MoveListStruct List of moves

func (*MoveListStruct) Print

func (list *MoveListStruct) Print()

Print prints the move list struct to console

type MoveStruct

type MoveStruct struct {
	Move  int
	Score int
}

MoveStruct used to store a move

type PositionStruct

type PositionStruct struct {
	Pieces      [SquareNumber]int
	Pawns       [3]uint64
	KingSquare  [2]int
	PieceNum    [13]int
	BigPieces   [2]int
	MajorPieces [2]int
	MinorPieces [2]int
	Material    [2]int

	CastelPerm int
	Side       int
	EnPassant  int
	FiftyMove  int
	Ply        int
	HisPly     int
	PosKey     uint64

	History [2048]UndoStruct

	PieceList [13][10]int

	HashTable HashTableStruct
	PvArray   [MaxDepth]int

	SearchHistory [13][SquareNumber]int
	SearchKillers [2][MaxDepth]int
}

PositionStruct the boards struct

func (*PositionStruct) CheckBoard

func (pos *PositionStruct) CheckBoard() error

CheckBoard VERY expensive only use for debugging

func (*PositionStruct) ClearMoveFromHash

func (pos *PositionStruct) ClearMoveFromHash() error

ClearMoveFromHash Clear the move made at the current position from the hash table

func (*PositionStruct) Evaluate

func (pos *PositionStruct) Evaluate() int

Evaluate the currect position and return a score

func (*PositionStruct) GenerateAllCaptureMoves

func (pos *PositionStruct) GenerateAllCaptureMoves(list *MoveListStruct) error

GenerateAllMoves Generate all moves

func (*PositionStruct) GenerateAllMoves

func (pos *PositionStruct) GenerateAllMoves(list *MoveListStruct) error

GenerateAllMoves Generate all moves

func (*PositionStruct) GetPvLine

func (pos *PositionStruct) GetPvLine(depth int) (int, error)

GetPvLine return the PVLine if found for the curren position

func (*PositionStruct) IsAttacked

func (pos *PositionStruct) IsAttacked(sq, side int) (bool, error)

IsAttacked Returns if square is attacked

func (*PositionStruct) IsRepition

func (pos *PositionStruct) IsRepition() bool

IsRepition tests for 3 fold repitition

func (*PositionStruct) LoadFEN

func (pos *PositionStruct) LoadFEN(fen string) error

LoadFEN loads the engine with a new board position from a FEN string

func (*PositionStruct) MakeMove

func (pos *PositionStruct) MakeMove(move int) (bool, error)

MakeMove Make a move if legal and return legality

func (*PositionStruct) MakeNullMove

func (pos *PositionStruct) MakeNullMove() error

MakeNullMove Make a null move

For more info go to https://www.chessprogramming.org/Null_Move_Pruning

func (*PositionStruct) MirrorBoard

func (pos *PositionStruct) MirrorBoard() error

mirrorBoard Mirror the position

func (*PositionStruct) MoveExists

func (pos *PositionStruct) MoveExists(move int) (bool, error)

func (*PositionStruct) ParseMove

func (pos *PositionStruct) ParseMove(move string) (int, error)

ParseMove algebraic notation to move int

func (*PositionStruct) Perft

func (pos *PositionStruct) Perft(depth int) (int, error)

Perft is a performance test used to test move generation

returns leaf node count

For more information of Perft: https://www.chessprogramming.org/Perft

func (*PositionStruct) PerftDivide

func (pos *PositionStruct) PerftDivide(depth int) error

PerftDivide divides the result of Perft() to each root node

returns leaf node count for a given root node

For more information of Perft: https://www.chessprogramming.org/Perft

func (*PositionStruct) Print

func (pos *PositionStruct) Print()

Print a representation of the current board state to the console

func (*PositionStruct) ProbeHashEntry

func (pos *PositionStruct) ProbeHashEntry(move *int, score *int, alpha, beta, depth int) (bool, error)

func (*PositionStruct) ProbePVMove

func (pos *PositionStruct) ProbePVMove() (int, error)

ProbePVTable probe the table for a move on the current position

func (*PositionStruct) StoreHashEntry

func (pos *PositionStruct) StoreHashEntry(move, score, flags, depth int) error

StorePVMove a move in the PV table

func (*PositionStruct) TakeMove

func (pos *PositionStruct) TakeMove() error

TakeMove Take back the last move

func (*PositionStruct) TakeNullMove

func (pos *PositionStruct) TakeNullMove() error

TakeNullMove Take back the last null move

type UndoStruct

type UndoStruct struct {
	Move       int
	CastelPerm int
	EnPassant  int
	FiftyMove  int
	PosKey     uint64
}

UndoStruct the undo move struct

Jump to

Keyboard shortcuts

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