hclibs

package
v0.0.0-...-1e1a600 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package hclibs ... Hastychess, Copyright (C) GPLv3, 2016, Kevin Colyer

Zorbist hashing functions (replaces a naive system of hashmaps and text string keys)

Hastychess, Copyright (C) GPLv3, 2016, Kevin Colyer

Index

Constants

View Source
const (
	UNINITIALISED = 0
	QUIET         = 50 // sorted by history
	ENPASSANT     = 51
	KILLERS       = 100
	O_O_O         = 200
	O_O           = 201
	BADCAPTURE    = 300
	EPCAPTURE     = 301
	CAPTURE       = 400
	GOODCAPTURE   = 500
	PROMOTE       = 600
	PVBONUS       = 700
	INCHECK       = 800
)
View Source
const (
	A1, B1, C1, D1, E1, F1, G1, H1 = iota<<4 + 0, iota<<4 + 1, iota<<4 + 2, iota<<4 + 3, iota<<4 + 4, iota<<4 + 5, iota<<4 + 6, iota<<4 + 7
	A2, B2, C2, D2, E2, F2, G2, H2 = iota<<4 + 0, iota<<4 + 1, iota<<4 + 2, iota<<4 + 3, iota<<4 + 4, iota<<4 + 5, iota<<4 + 6, iota<<4 + 7
	A3, B3, C3, D3, E3, F3, G3, H3 = iota<<4 + 0, iota<<4 + 1, iota<<4 + 2, iota<<4 + 3, iota<<4 + 4, iota<<4 + 5, iota<<4 + 6, iota<<4 + 7
	A4, B4, C4, D4, E4, F4, G4, H4 = iota<<4 + 0, iota<<4 + 1, iota<<4 + 2, iota<<4 + 3, iota<<4 + 4, iota<<4 + 5, iota<<4 + 6, iota<<4 + 7
	A5, B5, C5, D5, E5, F5, G5, H5 = iota<<4 + 0, iota<<4 + 1, iota<<4 + 2, iota<<4 + 3, iota<<4 + 4, iota<<4 + 5, iota<<4 + 6, iota<<4 + 7
	A6, B6, C6, D6, E6, F6, G6, H6 = iota<<4 + 0, iota<<4 + 1, iota<<4 + 2, iota<<4 + 3, iota<<4 + 4, iota<<4 + 5, iota<<4 + 6, iota<<4 + 7
	A7, B7, C7, D7, E7, F7, G7, H7 = iota<<4 + 0, iota<<4 + 1, iota<<4 + 2, iota<<4 + 3, iota<<4 + 4, iota<<4 + 5, iota<<4 + 6, iota<<4 + 7
	A8, B8, C8, D8, E8, F8, G8, H8 = iota<<4 + 0, iota<<4 + 1, iota<<4 + 2, iota<<4 + 3, iota<<4 + 4, iota<<4 + 5, iota<<4 + 6, iota<<4 + 7
)
View Source
const (
	PROTOCONSOLE = iota + 1
	PROTOXBOARD
	PROTOUCI
)
View Source
const BISHOP = 5
View Source
const BLACK = 1
View Source
const CHECK = 20000 // sign dictates who we award it to
View Source
const CHECKMATE = 200000 // 200_000
View Source
const EAST = 1
View Source
const EMPTY = 0

WHITE

View Source
const ENDGAME = 2
View Source
const ETTHASH = 4
View Source
const INF = -NEGINF
View Source
const KING = 6
View Source
const KS = 1
View Source
const MAXSEARCHDEPTH = 10 // for manual play - easier to know what you have done wrong
View Source
const MAXSEARCHDEPTHX = 8 // for xboard
View Source
const MIDGAME = 1
View Source
const NE = NORTH + EAST
View Source
const NEGINF = -1000001 // -1_000_001
View Source
const NIGHT = 3
View Source
const NN = 32
View Source
const NORTH = 16
View Source
const NW = NORTH + WEST
View Source
const OPENING = 0
View Source
const PAWN = 1
View Source
const POSINF = INF
View Source
const PREVENTEXPLOSION = 2000000 // 2mil nodes to made debugging easier!!! TODO remove!
View Source
const PTTHASH = 3
View Source
const QS = 0
View Source
const QSTTHASH = 2
View Source
const QUEEN = 7
View Source
const QUIESCEDEPTH = 4
View Source
const ROOK = 4
View Source
const SE = SOUTH + EAST
View Source
const SOUTH = -16
View Source
const SS = -32
View Source
const STALEMATE = 0 // 50000
View Source
const STARTFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
View Source
const SW = SOUTH + WEST
View Source
const TTEXACT = 1
View Source
const TTHASH = 1
View Source
const TTLOWER = 2
View Source
const TTMAXSIZE = 20 // (is 2^20=1048576 entries when over this oldest tt nodes are culled back so tt is this size
View Source
const TTUPPER = 3
View Source
const VERSION = "1.11 'Blockhead'"
View Source
const WEST = -1
View Source
const WHITE = 0

Variables

View Source
var BM = [4]int{NE, NW, SE, SW}
View Source
var GRID = [64]int{
	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,
}
View Source
var KM = [8]int{NORTH, EAST, WEST, SOUTH, NE, NW, SE, SW}

leapers

View Source
var NM = [8]int{31, 33, -31, -33, 14, 18, -14, -18}
View Source
var PM = [2][4]int{
	[4]int{NW, NORTH, NE, NN},
	[4]int{SE, SOUTH, SW, SS},
}

pawn

View Source
var Pst [3][16][128]int

piece square table is for 3 phases of game, 12 different pieces and the game board squares for each

View Source
var QM = [8]int{NORTH, EAST, WEST, SOUTH, NE, NW, SE, SW}
View Source
var REVGRID = [64]int{
	A8, B8, C8, D8, E8, F8, G8, H8,
	A7, B7, C7, D7, E7, F7, G7, H7,
	A6, B6, C6, D6, E6, F6, G6, H6,
	A5, B5, C5, D5, E5, F5, G5, H5,
	A4, B4, C4, D4, E4, F4, G4, H4,
	A3, B3, C3, D3, E3, F3, G3, H3,
	A2, B2, C2, D2, E2, F2, G2, H2,
	A1, B1, C1, D1, E1, F1, G1, H1,
}

REVGRID ... this is actually how we display the board on a screen or in FEN - top down !

View Source
var RM = [4]int{NORTH, EAST, WEST, SOUTH}
View Source
var Zhash zhashstruct

Functions

func Abs

func Abs(n int) int

func AlgToDec

func AlgToDec(alg string) int

func BLIND

func BLIND(m Move, p *Pos) bool

Cargo culted from see.cpp of CPW engine ***************************************************************************** * This is not yet proper static exchange evaluation, but an approximation * * proposed by Harm Geert Mueller under the acronym BLIND (better, or lower * * if not defended. As the name indicates, it detects only obviously good * * captures, but it seems enough to improve move ordering. * *****************************************************************************

func BoardToFEN

func BoardToFEN(p *Pos) string

func BoardToStr

func BoardToStr(p *Pos) string

func BoardToStrColour

func BoardToStrColour(p *Pos) string

func BoardToStrWide

func BoardToStrWide(p *Pos) string

func Comma

func Comma(i int) string

func Commaf

func Commaf(i float64) string

func DecToAlg

func DecToAlg(dec int) string

func DeepPerftTest

func DeepPerftTest(t *testing.T)

func Die

func Die(e string)

func Divide

func Divide(depth int, p *Pos) (nodesTotal int, s string)

the useful divide function shows counts of nodes for top level moves

func DoesMoveCheckKing

func DoesMoveCheckKing(m, Move, p *Pos) (b bool)

func Eval

func Eval(p *Pos, nummoves, gamestage int) int

func EvalQ

func EvalQ(p *Pos, nummoves, gamestage int) int

func GameInit

func GameInit()

func Gamestage

func Gamestage(p *Pos) int

func InCheck

func InCheck(king, side int, p *Pos) bool

func InitBook

func InitBook()

func InitHashSize

func InitHashSize(size int) (e error)

initialises the hash to the size that the engine will set. size is given in human terms of number of entries e.g. 32M=32 million byte / 8 this needs to always be done only once. ics engine sends a command to do this. Xboard also. Conoles we keep it set at

func IsAttacked

func IsAttacked(square, side int, p *Pos) bool

Is attacked - answers question is SQUARE attacked by SIDE

func IsLegalMove

func IsLegalMove(m Move, p *Pos) (retval, check bool)

func IsValidMove

func IsValidMove(m Move, p *Pos) bool

func KingIsNear

func KingIsNear(look int, p *Pos) bool

func MVVLVA

func MVVLVA(m Move, p *Pos) int

Most Valuable Victim, Least Valuable Agressor best captures scored high, worst lowest (or negative)

func MakeMove

func MakeMove(m Move, p *Pos)

func MakeUserMove

func MakeUserMove(m Move, p *Pos) (s string)

func Max

func Max(a, b int) int

func MhDistance

func MhDistance(from, to int) int

func Milliseconds

func Milliseconds(d time.Duration) int

func Min

func Min(a, b int) int

func MoveToAlg

func MoveToAlg(m Move) (s string)

func MoveToSAN

func MoveToSAN(move Move) (san string)

func NewRBCFEN

func NewRBCFEN(diff int) string

func Offboard

func Offboard(i int) bool

func Onboard

func Onboard(i int) bool

func OrderMoves

func OrderMoves(moves *[]Move, p *Pos, pv *PV) bool

func OtherSide

func OtherSide(p Pos) int

func Perft

func Perft(depth int, p *Pos) (nodes int)

total count of nodes of a given depth

func Pick

func Pick(i int) int

func PieceColour

func PieceColour(piece int) int

func PieceType

func PieceType(p int) int

func PstScore

func PstScore(p *Pos, nummoves, gamestage int) (score int)

TODO test coverage here!!!!

func Rand64Reset

func Rand64Reset()

func SearchQuiesce

func SearchQuiesce(p *Pos, alpha, beta int, plys int, qdepth int, searchdepth int, srch *Search) int

func Side

func Side(piece int) int

func TTClear

func TTClear(hashtable int) bool

func TTPerft

func TTPerft(depth int, p *Pos) (nodes int)

Uses TT to do the same thing

func TTPoke

func TTPoke(key Hash, hashtable int, data TtData)

func TtKey

func TtKey(p *Pos) string

Simple stringification why to make a TT table (used for book)

func UnMakeMove

func UnMakeMove(m Move, p *Pos) bool

func Xside

func Xside(side int) int

Types

type EngineInfo

type EngineInfo struct {
	//Pv    *PV
	//Stats *Statistics
	Pv    PV
	Stats Statistics
	Info  string
}

func NewEngineInfo

func NewEngineInfo(srch Search) EngineInfo

type Fen

type Fen string

func (Fen) NewBoard

func (f Fen) NewBoard() Pos

type Hash

type Hash uint64

func Rand64

func Rand64() Hash

Rand64 generates uint64's and is pinched the one the cpw engine pinches from Sungorus!

func TTZKey

func TTZKey(p *Pos) (z Hash)

make TtKey - scan board for pieces, xor in, xor in castling states, xor in side to move and EP

type History

type History struct {
	TakenPieces   [2]int
	JustTaken     int
	Castled       [4]bool
	King          [2]int
	Side          int
	InCheck       int // -1 == no side in check either 1 or 0
	EnPassant     int // -1 == not in enpassant otherwise square to check
	Fifty         int
	FullMoveClock int
	HalfMoveClock int
	Hash          Hash
	// contains filtered or unexported fields
}

type Move

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

////////////////////////////////////////////////////////////////////////

func AlgToMove

func AlgToMove(s string) (move Move)

func ChooseBookMove

func ChooseBookMove(p *Pos) (move Move, success bool)

func GenerateAllMoves

func GenerateAllMoves(p *Pos) (moves []Move)

func GenerateAllPseudoMoves

func GenerateAllPseudoMoves(p *Pos) (moves []Move)

func GenerateMoves

func GenerateMoves(from int, p *Pos) (moves []Move)

func GenerateMovesForQSearch

func GenerateMovesForQSearch(p *Pos) (moves []Move)

func ParseUserMove

func ParseUserMove(input string, p *Pos) (m Move, err string)

func SearchRoot

func SearchRoot(p *Pos, srch *Search) (bestmove Move, bestscore int)

THIS SHOULD BE SEARCH ROOT OR A WAY TO ALLOW ME TO PLUG IN DIFFERENT SEARCHES

func (Move) String

func (mv Move) String() string

type Movescore

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

/////////////////////////////////////////////////////////////////////

type PV

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

//////////////////////////////////////////////////////////////////////// PV struct

func (PV) String

func (pv PV) String() (res string)

pretty printer for PV struct

type Pos

type Pos struct {
	FEN           string
	Board         [128]int /* 0x88 board */
	TakenPieces   [2]int
	Castled       [4]bool
	King          [2]int
	Side          int
	InCheck       int // -1 == no side in check either 1 or 0
	EnPassant     int // -1 == not in enpassant otherwise square to check
	Fifty         int
	FullMoveClock int
	HalfMoveClock int
	Ply           int
	Hash          Hash
}

////////////////////////////////////////////////////////////////////////

func FENToBoard

func FENToBoard(f string, p *Pos) *Pos

func FENToNewBoard

func FENToNewBoard(f string) Pos

func (*Pos) String

func (p *Pos) String() string

type Proto

type Proto int
type Search struct {
	Stats *Statistics

	TimeStart           time.Time
	MaxDurationOfSearch time.Duration

	FEN          Fen
	P            *Pos
	NewFEN       Fen
	HistoryTable [128][128]int
	KillerTable  [128][128]int

	Result           string
	Info             string
	PV               *PV
	Score            int
	BestMove         Move
	Stop             bool
	ExplosionLimit   int
	MaxDepthToSearch int

	EngineInfoChan chan EngineInfo
	UseTT          bool
	UseBook        bool
}

func Go

func Go(p *Pos, eiChan chan EngineInfo) (res string, info string, srch *Search)

func NewSearch

func NewSearch(FEN Fen) *Search

func (Search) Search

func (srch Search) Search(depth int) (completed bool)

func (Search) StopSearch

func (srch Search) StopSearch() bool

type Statistics

type Statistics struct {
	Score             int
	Nodes             int
	QNodes            int
	MaxDepthSearched  int
	MaxQDepthSearched int
	TtHits            int
	TtWrites          int
	TtCulls           int
	TtUpdates         int
	UpperCuts         int
	LowerCuts         int
	AlphaRaised       int
	BetaRaised        int
	HtWrite           int
	HtHit             int
	KiWrite           int
	KiHit             int
	TimeElapsed       time.Duration
}

func (Statistics) String

func (stat Statistics) String() string

type TtData

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

func TTPeek

func TTPeek(key Hash, hashtable int) (data TtData, err bool)

Jump to

Keyboard shortcuts

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