types

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package types contains various user defined data types and their corresponding functionality we need for the chess engine. Many of these would be perfect enum candidates but GO does not provide enums

Index

Constants

View Source
const (
	BbZero = Bitboard(0)
	BbAll  = ^BbZero
	BbOne  = Bitboard(1)

	FileA_Bb Bitboard = 0x0101010101010101
	FileB_Bb          = FileA_Bb << 1
	FileC_Bb          = FileA_Bb << 2
	FileD_Bb          = FileA_Bb << 3
	FileE_Bb          = FileA_Bb << 4
	FileF_Bb          = FileA_Bb << 5
	FileG_Bb          = FileA_Bb << 6
	FileH_Bb          = FileA_Bb << 7

	Rank1_Bb Bitboard = 0xFF
	Rank2_Bb          = Rank1_Bb << (8 * 1)
	Rank3_Bb          = Rank1_Bb << (8 * 2)
	Rank4_Bb          = Rank1_Bb << (8 * 3)
	Rank5_Bb          = Rank1_Bb << (8 * 4)
	Rank6_Bb          = Rank1_Bb << (8 * 5)
	Rank7_Bb          = Rank1_Bb << (8 * 6)
	Rank8_Bb          = Rank1_Bb << (8 * 7)

	MsbMask   = ^(Bitboard(1) << 63)
	Rank8Mask = ^Rank8_Bb
	FileAMask = ^FileA_Bb
	FileHMask = ^FileH_Bb

	DiagUpA1 Bitboard = 0b10000000_01000000_00100000_00010000_00001000_00000100_00000010_00000001
	DiagUpB1          = (MsbMask & DiagUpA1) << 1 & FileAMask // shift EAST
	DiagUpC1          = (MsbMask & DiagUpB1) << 1 & FileAMask
	DiagUpD1          = (MsbMask & DiagUpC1) << 1 & FileAMask
	DiagUpE1          = (MsbMask & DiagUpD1) << 1 & FileAMask
	DiagUpF1          = (MsbMask & DiagUpE1) << 1 & FileAMask
	DiagUpG1          = (MsbMask & DiagUpF1) << 1 & FileAMask
	DiagUpH1          = (MsbMask & DiagUpG1) << 1 & FileAMask
	DiagUpA2          = (Rank8Mask & DiagUpA1) << 8 // shift NORTH
	DiagUpA3          = (Rank8Mask & DiagUpA2) << 8
	DiagUpA4          = (Rank8Mask & DiagUpA3) << 8
	DiagUpA5          = (Rank8Mask & DiagUpA4) << 8
	DiagUpA6          = (Rank8Mask & DiagUpA5) << 8
	DiagUpA7          = (Rank8Mask & DiagUpA6) << 8
	DiagUpA8          = (Rank8Mask & DiagUpA7) << 8

	DiagDownH1 Bitboard = 0b0000000100000010000001000000100000010000001000000100000010000000
	DiagDownH2          = (Rank8Mask & DiagDownH1) << 8 // shift NORTH
	DiagDownH3          = (Rank8Mask & DiagDownH2) << 8
	DiagDownH4          = (Rank8Mask & DiagDownH3) << 8
	DiagDownH5          = (Rank8Mask & DiagDownH4) << 8
	DiagDownH6          = (Rank8Mask & DiagDownH5) << 8
	DiagDownH7          = (Rank8Mask & DiagDownH6) << 8
	DiagDownH8          = (Rank8Mask & DiagDownH7) << 8
	DiagDownG1          = (DiagDownH1 >> 1) & FileHMask // shift WEST
	DiagDownF1          = (DiagDownG1 >> 1) & FileHMask
	DiagDownE1          = (DiagDownF1 >> 1) & FileHMask
	DiagDownD1          = (DiagDownE1 >> 1) & FileHMask
	DiagDownC1          = (DiagDownD1 >> 1) & FileHMask
	DiagDownB1          = (DiagDownC1 >> 1) & FileHMask
	DiagDownA1          = (DiagDownB1 >> 1) & FileHMask

	CenterFiles   = FileD_Bb | FileE_Bb
	CenterRanks   = Rank4_Bb | Rank5_Bb
	CenterSquares = CenterFiles & CenterRanks
)

Various constant bitboards

View Source
const (
	CastlingNone CastlingRights = 0 // 0000

	CastlingWhiteOO  CastlingRights = 1                                  // 0001
	CastlingWhiteOOO                = CastlingWhiteOO << 1               // 0010
	CastlingWhite                   = CastlingWhiteOO | CastlingWhiteOOO // 0011

	CastlingBlackOO  = CastlingWhiteOO << 2               // 0100
	CastlingBlackOOO = CastlingBlackOO << 1               // 1000
	CastlingBlack    = CastlingBlackOO | CastlingBlackOOO // 1100

	CastlingAny                         = CastlingWhite | CastlingBlack // 1111
	CastlingRightsLength CastlingRights = 16
)

Constants for Castling

View Source
const (
	White       Color = 0
	Black       Color = 1
	ColorLength int   = 2
)

Constants for each color

View Source
const (
	// SqLength number of squares on a board
	SqLength int = 64

	// MaxDepth max search depth
	MaxDepth = 128

	// MaxMoves max number of moves for a game
	MaxMoves = 512

	// KB = 1.024 bytes
	KB uint64 = 1024

	// MB = KB * KB
	MB = KB * KB

	// GB = KB * MB
	GB = KB * MB

	// GamePhaseMax maximum game phase value. Game phase is used to
	// determine if we are in the beginning or end phase of a chess game
	// Game phase is calculated be the number of officers on the board
	// with this maximum
	GamePhaseMax = 24
)
View Source
const (
	ValueZero               Value = 0
	ValueDraw               Value = 0
	ValueOne                Value = 1
	ValueInf                Value = 15_000
	ValueNA                       = -ValueInf - 1
	ValueMax                Value = 10_000
	ValueMin                      = -ValueMax
	ValueCheckMate                = ValueMax
	ValueCheckMateThreshold       = ValueCheckMate - MaxDepth - 1
)

Constants for values

View Source
const (
	Vnone   ValueType = 0
	EXACT   ValueType = 1
	ALPHA   ValueType = 2 // upper bound
	BETA    ValueType = 3 // lower bound
	Vlength int       = 4
)

ValueType is a set of constants for value types used in search and TtTable noinspection GoVarAndConstTypeMayBeOmitted

Variables

Functions

func FileDistance

func FileDistance(f1 File, f2 File) int

FileDistance returns the absolute distance in squares between two files

func RankDistance

func RankDistance(r1 Rank, r2 Rank) int

RankDistance returns the absolute distance in squares between two ranks

func SquareDistance

func SquareDistance(s1 Square, s2 Square) int

SquareDistance returns the absolute distance in squares between two squares

Types

type Bitboard

type Bitboard uint64

Bitboard is a 64 bit unsigned int with 1 bit for each square on the board

func GetAttacksBb

func GetAttacksBb(pt PieceType, sq Square, occupied Bitboard) Bitboard

GetAttacksBb returns a bitboard representing all the squares attacked by a piece of the given type pt (not pawn) placed on 'sq'. For sliding pieces this uses the pre-computed Magic Bitboard Attack arrays. For Knight and King this the occupied Bitboard is ignored (can be BbZero) as for these non sliders the pre-computed pseudo attacks are used

func GetMovesDiagDown

func GetMovesDiagDown(square Square, content Bitboard) Bitboard

GetMovesDiagDown Bb for all possible diagonal up moves of the square with the content (blocking pieces) determined from the given non rotated bitboard.

Deprecated use GetAttacksBb(pt PieceType, sq Square, occupied Bitboard)

func GetMovesDiagDownRotated

func GetMovesDiagDownRotated(sq Square, rotated Bitboard) Bitboard

GetMovesDiagDownRotated Bb for all possible diagonal up moves of the square with the content (blocking pieces) determined from the given L45 rotated bitboard.

Deprecated use GetAttacksBb(pt PieceType, sq Square, occupied Bitboard)

func GetMovesDiagUp

func GetMovesDiagUp(sq Square, content Bitboard) Bitboard

GetMovesDiagUp Bb for all possible diagonal up moves of the square with the content (blocking pieces) determined from the given non rotated bitboard.

Deprecated use GetAttacksBb(pt PieceType, sq Square, occupied Bitboard)

func GetMovesDiagUpRotated

func GetMovesDiagUpRotated(sq Square, rotated Bitboard) Bitboard

GetMovesDiagUpRotated Bb for all possible diagonal up moves of the square with the content (blocking pieces) determined from the given R45 rotated bitboard.

Deprecated use GetAttacksBb(pt PieceType, sq Square, occupied Bitboard)

func GetMovesOnFile

func GetMovesOnFile(sq Square, content Bitboard) Bitboard

GetMovesOnFile Bb for all possible horizontal moves on the rank of the square with the rank content (blocking pieces) determined from the given bitboard (not rotated - use GetMovesOnFileRotated for already rotated bitboards)

Deprecated use GetAttacksBb(pt PieceType, sq Square, occupied Bitboard)

func GetMovesOnFileRotated

func GetMovesOnFileRotated(sq Square, rotated Bitboard) Bitboard

GetMovesOnFileRotated Bb for all possible horizontal moves on the rank of the square with the rank content (blocking pieces) determined from the given L90 rotated bitboard.

Deprecated use GetAttacksBb(pt PieceType, sq Square, occupied Bitboard)

func GetMovesOnRank

func GetMovesOnRank(sq Square, content Bitboard) Bitboard

GetMovesOnRank returns a Bb for all possible horizontal moves on the rank of the square with the rank content (blocking pieces) determined from the given pieces bitboard.

Deprecated use GetAttacksBb(pt PieceType, sq Square, occupied Bitboard)

func GetPawnAttacks

func GetPawnAttacks(c Color, sq Square) Bitboard

GetPawnAttacks returns a Bb of possible attacks of a pawn

func GetPseudoAttacks

func GetPseudoAttacks(pt PieceType, sq Square) Bitboard

GetPseudoAttacks returns a Bb of possible attacks of a piece as if on an empty board

func Intermediate

func Intermediate(sq1 Square, sq2 Square) Bitboard

Intermediate returns a Bb of squares between the given two squares

func KingSideCastleMask

func KingSideCastleMask(c Color) Bitboard

KingSideCastleMask returns a Bb with the kings side squares used in castling without the king square

func PopSquare

func PopSquare(b Bitboard, s Square) Bitboard

PopSquare removes the corresponding bit of the bitboard for the square

func PushSquare

func PushSquare(b Bitboard, s Square) Bitboard

PushSquare sets the corresponding bit of the bitboard for the square

func QueenSideCastMask

func QueenSideCastMask(c Color) Bitboard

QueenSideCastMask returns a Bb with the queen side squares used in castling without the king square

func RotateL45

func RotateL45(b Bitboard) Bitboard

RotateL45 rotates a Bb by 45 degrees counter clockwise to get all downward diagonals in compact block of bits This is used to create a mask to find moves for queen and bishop on the downward diagonal

func RotateL90

func RotateL90(b Bitboard) Bitboard

RotateL90 rotates a Bb by 90 degrees counter clockwise

func RotateR45

func RotateR45(b Bitboard) Bitboard

RotateR45 rotates a Bb by 45 degrees clockwise to get all upward diagonals in compact block of bits This is used to create a mask to find moves for queen and bishop on the upward diagonal

func RotateR90

func RotateR90(b Bitboard) Bitboard

RotateR90 rotates a Bb by 90 degrees clockwise

func ShiftBitboard

func ShiftBitboard(b Bitboard, d Direction) Bitboard

ShiftBitboard shifting all bits of a bitboard in the given direction by 1 square

func SquaresBb

func SquaresBb(c Color) Bitboard

SquaresBb returns a Bb of all squares of the given color. E.g. can be used to find bishops of the same "color" for draw detection.

func (Bitboard) Has

func (b Bitboard) Has(s Square) bool

Has tests if a square (bit) is set

func (Bitboard) Lsb

func (b Bitboard) Lsb() Square

Lsb returns the least significant bit of the 64-bit Bb. This translates directly to the Square which is returned. If the bitboard is empty SqNone will be returned. Lsb() indexes from 0-63 - 0 being the the lsb and equal to SqA1

func (Bitboard) Msb

func (b Bitboard) Msb() Square

Msb returns the most significant bit of the 64-bit Bb. This translates directly to the Square which is returned. If the bitboard is empty SqNone will be returned. Msb() indexes from 0-63 - 63 being the the msb and equal to SqH8

func (Bitboard) PopCount

func (b Bitboard) PopCount() int

PopCount returns the number of one bits ("population count") in b. This equals the number of squares set in a Bitboard

func (*Bitboard) PopLsb

func (b *Bitboard) PopLsb() Square

PopLsb returns the Lsb square and removes it from the bitboard. The given bitboard is changed directly.

func (*Bitboard) PopSquare

func (b *Bitboard) PopSquare(s Square) Bitboard

PopSquare removes the corresponding bit of the bitboard for the square

func (*Bitboard) PushSquare

func (b *Bitboard) PushSquare(s Square) Bitboard

PushSquare sets the corresponding bit of the bitboard for the square

func (Bitboard) String

func (b Bitboard) String() string

String returns a string representation of the 64 bits

func (Bitboard) StringBoard

func (b Bitboard) StringBoard() string

StringBoard returns a string representation of the Bb as a board off 8x8 squares

func (Bitboard) StringGrouped

func (b Bitboard) StringGrouped() string

StringGrouped returns a string representation of the 64 bits grouped in 8. Order is LSB to msb ==> A1 B1 ... G8 H8

type CastlingRights

type CastlingRights uint8

CastlingRights encodes the castling state e.g. available castling and defines functions to change this state

func GetCastlingRights

func GetCastlingRights(sq Square) CastlingRights

GetCastlingRights returns the CastlingRights for changes on this square.

func (*CastlingRights) Add

Add adds a castling right ti the state

func (CastlingRights) Has

func (cr CastlingRights) Has(rhs CastlingRights) bool

Has checks if the state has the bit for the Castling right set and therefore this castling is available

func (*CastlingRights) Remove

Remove removes a castling right from the input state (deletes right)

func (CastlingRights) String

func (cr CastlingRights) String() string

String returns a string representation for the castling right instance which can be used directly in a fen (e.g. "KQkq")

type Color

type Color uint8

Color represents constants for each chess color White and Black

func (Color) Direction

func (c Color) Direction() int

Direction returns positive 1 for White and negative 1 (-1) for Black

func (Color) Flip

func (c Color) Flip() Color

Flip returns the opposite color

func (Color) IsValid

func (c Color) IsValid() bool

IsValid checks if f represents a valid color

func (Color) MoveDirection

func (c Color) MoveDirection() Direction

MoveDirection returns the direction of a pawn move for the color

func (Color) PawnDoubleRank

func (c Color) PawnDoubleRank() Bitboard

PawnDoubleRank returns the rank from which the given color might make a second pawn push to achieve a pawn double move

func (Color) PromotionRankBb

func (c Color) PromotionRankBb() Bitboard

PromotionRankBb returns the rank on which the given color promotes

func (Color) String

func (c Color) String() string

String returns a string representation of color as "w" or "b"

type Direction

type Direction int8

Direction is a set of constants for moving squares within a Bb

const (
	North     Direction = 8
	East      Direction = 1
	South     Direction = -North
	West      Direction = -East
	Northeast Direction = North + East
	Southeast Direction = South + East
	Southwest Direction = South + West
	Northwest Direction = North + West
)

Direction is a set of constants for moving squares within a Bb noinspection GoVarAndConstTypeMayBeOmitted

func (Direction) String

func (d Direction) String() string

String returns a string representation of a Direction (e.g. N, E, ...,NW,...)

type File

type File uint8

File represents a chess board file a-h

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

File represents a chess board file a-h noinspection GoUnusedConst

func (File) Bb

func (f File) Bb() Bitboard

Bb returns a Bitboard of the given file

func (File) IsValid

func (f File) IsValid() bool

IsValid checks if f represents a valid file

func (File) String

func (f File) String() string

String returns a string letter for the file (e.g. a - h) if f is not a valid file returns "-"

type Magic

type Magic struct {
	Mask    Bitboard
	Magic   Bitboard
	Attacks []Bitboard
	Shift   uint
}

Magic holds all magic bitboards relevant for a single square Taken from Stockfish License see https://stockfishchess.org/about/

type Move

type Move uint32

Move is a 32bit unsigned int type for encoding chess moves as a primitive data type 16 bits for move encoding - 16 bits for sort value

const (
	// MoveNone empty non valid move
	MoveNone Move = 0
)

func CreateMove

func CreateMove(from Square, to Square, t MoveType, promType PieceType) Move

CreateMove returns an encoded Move instance

func CreateMoveValue

func CreateMoveValue(from Square, to Square, t MoveType, promType PieceType, value Value) Move

CreateMoveValue returns an encoded Move instance including a sort value

func (Move) From

func (m Move) From() Square

From returns the from-Square of the move

func (Move) IsValid

func (m Move) IsValid() bool

IsValid check if the move has valid squares, promotion type and move type. MoveNone is not a valid move in this sense.

func (Move) MoveOf

func (m Move) MoveOf() Move

MoveOf returns the move without any value (least 16-bits)

func (Move) MoveType

func (m Move) MoveType() MoveType

MoveType returns the type of the move as defined in MoveType Normal, Promotion, EnPassant, Castling

func (Move) PromotionType

func (m Move) PromotionType() PieceType

PromotionType returns the PieceType considered for promotion when move type is also MoveType.Promotion. Must be ignored when move type is not MoveType.Promotion.

func (*Move) SetValue

func (m *Move) SetValue(v Value) Move

SetValue encodes the given value into the high 16-bit of the move

func (Move) String

func (m Move) String() string

String string representation of a move which is UCI compatible

func (Move) StringBits

func (m Move) StringBits() string

StringBits returns a string with details of a Move E.g. Move { From[001100](e2) To[011100](e4) Prom[11](N) tType[00](n) value[0000000000000000](0) (796)}

func (Move) StringUci

func (m Move) StringUci() string

StringUci string representation of a move which is UCI compatible

func (Move) To

func (m Move) To() Square

To returns the to-Square of the move

func (Move) ValueOf

func (m Move) ValueOf() Value

ValueOf returns the sort value for the move used in the move generator

type MoveType

type MoveType uint

MoveType is used for the different move types we use to encode moves. Values are Normal, Promotion, EnPassant, Castling

const (
	Normal    MoveType = 0
	Promotion MoveType = 1
	EnPassant MoveType = 2
	Castling  MoveType = 3
)

MoveType constants

func (MoveType) IsValid

func (t MoveType) IsValid() bool

IsValid checks if t is a valid move type

func (MoveType) String

func (t MoveType) String() string

String returns a string representing the move type

type Orientation

type Orientation uint8

Orientation is a set of constants for directions from a squares

const (
	NW Orientation = 0
	N  Orientation = 1
	NE Orientation = 2
	E  Orientation = 3
	SE Orientation = 4
	S  Orientation = 5
	SW Orientation = 6
	W  Orientation = 7
)

Orientation is a set of constants for moving squares within a Bb noinspection GoVarAndConstTypeMayBeOmitted

func (Orientation) IsValid

func (o Orientation) IsValid() bool

IsValid tests if o is a valid Orientation value

func (Orientation) String

func (d Orientation) String() string

String returns a string representation of a Orientation (e.g. N, E, ...,NW,...)

type Piece

type Piece int8

Piece is a set of constants for pieces in chess

const (
	PieceNone   Piece = 0
	WhiteKing   Piece = 1
	WhitePawn   Piece = 2
	WhiteKnight Piece = 3
	WhiteBishop Piece = 4
	WhiteRook   Piece = 5
	WhiteQueen  Piece = 6
	BlackKing   Piece = 9
	BlackPawn   Piece = 10
	BlackKnight Piece = 11
	BlackBishop Piece = 12
	BlackRook   Piece = 13
	BlackQueen  Piece = 14
	PieceLength Piece = 16
)

Pieces are a set of constants to represent the different pieces of a chess game.

Can be used with masks:

No Piece = 0
White Piece is a non zero value with piece & 0b1000 == 0
Black Piece is a non zero value with piece & 0b1000 == 1
PieceNone  = 0b0000
WhiteKing  = 0b0001
WhitePawn  = 0b0010
WhiteKnight= 0b0011
WhiteBishop= 0b0100
WhiteRook  = 0b0101
WhiteQueen = 0b0110
BlackKing  = 0b1001
BlackPawn  = 0b1010
BlackKnight= 0b1011
BlackBishop= 0b1100
BlackRook  = 0b1101
BlackQueen = 0b1110
PieceLength= 0b10000

func MakePiece

func MakePiece(c Color, pt PieceType) Piece

MakePiece creates the piece given by color and piece type

func PieceFromChar

func PieceFromChar(s string) Piece

PieceFromChar returns the Piece corresponding to the given character. If s contains not exactly one character or if the character is invalid this will return PieceNone

func (Piece) Char

func (p Piece) Char() string

Char returns a string representation of a piece type where pawns are O and * for white and black

func (Piece) ColorOf

func (p Piece) ColorOf() Color

ColorOf returns the color of the given piece */

func (Piece) String

func (p Piece) String() string

String returns a string representation of a piece type

func (Piece) TypeOf

func (p Piece) TypeOf() PieceType

TypeOf returns the piece type of the given piece */

func (Piece) ValueOf

func (p Piece) ValueOf() Value

ValueOf returns a value for calculating game phase by adding the number of certain piece type times this value

type PieceType

type PieceType int8

PieceType is a set of constants for piece types in chess

const (
	PtNone   PieceType = 0b0000
	King     PieceType = 0b0001
	Pawn     PieceType = 0b0010
	Knight   PieceType = 0b0011
	Bishop   PieceType = 0b0100
	Rook     PieceType = 0b0101
	Queen    PieceType = 0b0110
	PtLength PieceType = 0b0111
)

PieceType is a set of constants for piece types in chess

test for non sliding pt & 0b0100 == 0 (must be none zero)
test for sliding pt & 0b0100 == 1 (must be < 7)
PtNone   = 0b0000
King     = 0b0001 // non sliding
Pawn     = 0b0010 // non sliding
Knight   = 0b0011 // non sliding
Bishop   = 0b0100 // sliding
Rook     = 0b0101 // sliding
Queen    = 0b0110 // sliding
PtLength = 0b0111

func (PieceType) Char

func (pt PieceType) Char() string

Char returns a single char string representation of a piece type

func (PieceType) GamePhaseValue

func (pt PieceType) GamePhaseValue() int

GamePhaseValue returns a value for calculating game phase by adding the number of certain piece type times this value

func (PieceType) IsValid

func (pt PieceType) IsValid() bool

IsValid check if pt is a valid piece type

func (PieceType) String

func (pt PieceType) String() string

String returns a string representation of a piece type

func (PieceType) ValueOf

func (pt PieceType) ValueOf() Value

ValueOf returns a value for calculating game phase by adding the number of certain piece type times this value

type PrnG

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

PrnG random generator for magic bitboards from Stockfish xorshift64star Pseudo-Random Number Generator This class is based on original code written and dedicated to the public domain by Sebastiano Vigna (2014). It has the following characteristics:

  • Outputs 64-bit numbers
  • Passes Dieharder and SmallCrush test batteries
  • Does not require warm-up, no zeroland to escape
  • Internal state is a single 64-bit integer
  • Period is 2^64 - 1
  • Speed: 1.60 ns/call (Core i7 @3.40GHz)

For further analysis see

<http://vigna.di.unimi.it/ftp/papers/xorshift.pdf>

type Rank

type Rank uint8

Rank represents a chess board rank 1-8

const (
	Rank1      Rank = iota
	Rank2      Rank = iota
	Rank3      Rank = iota
	Rank4      Rank = iota
	Rank5      Rank = iota
	Rank6      Rank = iota
	Rank7      Rank = iota
	Rank8      Rank = iota
	RankNone   Rank = iota
	RankLength      = RankNone
)

Rank represents a chess board rank 1-8 noinspection GoUnusedConst

func (Rank) Bb

func (r Rank) Bb() Bitboard

Bb returns a Bitboard of the given rank

func (Rank) IsValid

func (r Rank) IsValid() bool

IsValid checks if f represents a valid file

func (Rank) String

func (r Rank) String() string

String returns a string letter for the file (e.g. a - h) if r is not a valid rank returns "-"

type Score

type Score struct {
	MidGameValue int
	EndGameValue int
}

Score is a small struct for mid game and end game values

func (*Score) Add

func (s *Score) Add(a Score)

Add adds the corresponding parts of the given score to the calling score

func (*Score) String

func (s *Score) String() string

func (*Score) Sub

func (s *Score) Sub(a Score)

Sub subtracts the corresponding parts of the given score from the calling score

func (*Score) ValueFromScore

func (s *Score) ValueFromScore(gpf float64) Value

ValueFromScore adds up the mid and end games scores after multiplying them with the game phase factor

type Square

type Square uint8

Square represent exactly on square on a chess board.

const (
	SqA1   Square = iota // 0
	SqB1   Square = iota // 1
	SqC1   Square = iota
	SqD1   Square = iota
	SqE1   Square = iota
	SqF1   Square = iota
	SqG1   Square = iota
	SqH1   Square = iota
	SqA2   Square = iota
	SqB2   Square = iota
	SqC2   Square = iota
	SqD2   Square = iota
	SqE2   Square = iota
	SqF2   Square = iota
	SqG2   Square = iota
	SqH2   Square = iota
	SqA3   Square = iota
	SqB3   Square = iota
	SqC3   Square = iota
	SqD3   Square = iota
	SqE3   Square = iota
	SqF3   Square = iota
	SqG3   Square = iota
	SqH3   Square = iota
	SqA4   Square = iota
	SqB4   Square = iota
	SqC4   Square = iota
	SqD4   Square = iota
	SqE4   Square = iota
	SqF4   Square = iota
	SqG4   Square = iota
	SqH4   Square = iota
	SqA5   Square = iota
	SqB5   Square = iota
	SqC5   Square = iota
	SqD5   Square = iota
	SqE5   Square = iota
	SqF5   Square = iota
	SqG5   Square = iota
	SqH5   Square = iota
	SqA6   Square = iota
	SqB6   Square = iota
	SqC6   Square = iota
	SqD6   Square = iota
	SqE6   Square = iota
	SqF6   Square = iota
	SqG6   Square = iota
	SqH6   Square = iota
	SqA7   Square = iota
	SqB7   Square = iota
	SqC7   Square = iota
	SqD7   Square = iota
	SqE7   Square = iota
	SqF7   Square = iota
	SqG7   Square = iota
	SqH7   Square = iota
	SqA8   Square = iota
	SqB8   Square = iota
	SqC8   Square = iota
	SqD8   Square = iota
	SqE8   Square = iota
	SqF8   Square = iota
	SqG8   Square = iota
	SqH8   Square = iota // 63
	SqNone Square = iota // 64
)

noinspection GoUnusedConst

func MakeSquare

func MakeSquare(s string) Square

MakeSquare returns a square based on the string given or SqNone if no valid square could be read from the string

func RotateSquareL45

func RotateSquareL45(sq Square) Square

RotateSquareL45 maps squares to the sq of the rotated board. E.g. when rotating clockwise by 90 degree A1 becomes A8, A8 becomes H8, etc.

func RotateSquareL90

func RotateSquareL90(sq Square) Square

RotateSquareL90 maps squares to the sq of the rotated board. E.g. when rotating clockwise by 90 degree A1 becomes A8, A8 becomes H8, etc.

func RotateSquareR45

func RotateSquareR45(sq Square) Square

RotateSquareR45 maps squares to the sq of the rotated board. E.g. when rotating clockwise by 90 degree A1 becomes A8, A8 becomes H8, etc.

func RotateSquareR90

func RotateSquareR90(sq Square) Square

RotateSquareR90 maps squares to the sq of the rotated board. E.g. when rotating clockwise by 90 degree A1 becomes A8, A8 becomes H8, etc.

func SquareOf

func SquareOf(f File, r Rank) Square

SquareOf returns a square from file and rank Returns SqNone for invalid files or ranks

func (Square) Bb

func (sq Square) Bb() Bitboard

Bb returns a Bitboard of the square by accessing the pre calculated square to bitboard array.

func (Square) CenterDistance

func (sq Square) CenterDistance() int

CenterDistance returns the distance to the nearest center square

func (Square) FileEastMask

func (sq Square) FileEastMask() Bitboard

FileEastMask returns a Bb of the file east of the square

func (Square) FileOf

func (sq Square) FileOf() File

FileOf returns the file of the square

func (Square) FileWestMask

func (sq Square) FileWestMask() Bitboard

FileWestMask returns a Bb of the file west of the square

func (Square) FilesEastMask

func (sq Square) FilesEastMask() Bitboard

FilesEastMask returns a Bb of the files east of the square

func (Square) FilesWestMask

func (sq Square) FilesWestMask() Bitboard

FilesWestMask returns a Bb of the files west of the square

func (Square) Intermediate

func (sq Square) Intermediate(sqTo Square) Bitboard

Intermediate returns a Bb of squares between the given two squares

func (Square) IsValid

func (sq Square) IsValid() bool

IsValid checks a value of type square if it represents a valid square on a chess board (e.q. sq < 64).

func (Square) NeighbourFilesMask

func (sq Square) NeighbourFilesMask() Bitboard

NeighbourFilesMask returns a Bb of the file east and west of the square

func (Square) PassedPawnMask

func (sq Square) PassedPawnMask(c Color) Bitboard

PassedPawnMask returns a Bitboards with all possible squares which have an opponents pawn which could stop this pawn. Use this mask and AND it with the opponents pawns bitboards to see if a pawn has passed.

func (Square) RankOf

func (sq Square) RankOf() Rank

RankOf returns the rank of the square

func (Square) RanksNorthMask

func (sq Square) RanksNorthMask() Bitboard

RanksNorthMask returns a Bb of the ranks north of the square

func (Square) RanksSouthMask

func (sq Square) RanksSouthMask() Bitboard

RanksSouthMask returns a Bb of the ranks south of the square

func (Square) Ray

func (sq Square) Ray(o Orientation) Bitboard

Ray returns a Bb of squares outgoing from the square in direction of the orientation

func (Square) String

func (sq Square) String() string

String returns a string of the file letter and rank number (e.g. e5) if the sq is not a valid square returns "-"

func (Square) To

func (sq Square) To(d Direction) Square

To returns the square on the chess board in the given direction

type Value

type Value int16

Value represents the positional value of a chess position

func Max added in v1.0.0

func Max(x, y Value) Value

Max returns the bigger of the given values

func Min added in v1.0.0

func Min(x, y Value) Value

Min returns the smaller of the given values

func PosEndValue

func PosEndValue(p Piece, sq Square) Value

PosEndValue returns the pre computed positional value for the piece on the given square in end game

func PosMidValue

func PosMidValue(p Piece, sq Square) Value

PosMidValue returns the pre computed positional value for the piece on the given square in mid game

func PosValue

func PosValue(p Piece, sq Square, gp int) Value

PosValue returns the pre computed positional value for the piece on the given square and given game phase

func (Value) IsCheckMateValue

func (v Value) IsCheckMateValue() bool

IsCheckMateValue returns true if value is above the check mate threshold which typically is set to check mate value minus the maximum search depth

func (Value) IsValid

func (v Value) IsValid() bool

IsValid checks if value is within valid range (between Min and Max)

func (Value) String

func (v Value) String() string

type ValueType

type ValueType int8

ValueType is a set of constants for value types used in search and TtTable

func (ValueType) IsValid

func (vt ValueType) IsValid() bool

IsValid check if pt is a valid value type

func (ValueType) String

func (vt ValueType) String() string

String returns a string representation of a piece type

Jump to

Keyboard shortcuts

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