engine

package
v0.0.0-...-c593c61 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Empty 无
	Empty int = iota
	// King 帅
	King
	// Rook 车
	Rook
	// Knight 马
	Knight
	// Cannon 炮
	Cannon
	// Advisor 士
	Advisor
	// Bishop 象
	Bishop
	// Pawn 兵
	Pawn
)
View Source
const MoveEmpty = Move(0)
View Source
const (
	SquareNone = -1
)

Variables

View Source
var (
	// GlobalBoard 全局 board.
	GlobalBoard = bitset.New(256)
	// RedBoard 红方 board.
	RedBoard = bitset.New(256)
	// BlackBoard 黑方 board.
	BlackBoard = bitset.New(256)

	// BoardMask 棋盘
	BoardMask = bitset.New(256)

	// FileMasks 列屏蔽
	FileMasks = []*bitset.BitSet{}

	// RankMasks 行屏蔽
	RankMasks = []*bitset.BitSet{}

	// RookAttacks 车攻击位置
	RookAttacks = make(map[int]*bitset.BitSet)

	// KnightAttacks 马攻击位置
	KnightAttacks = make(map[int]*bitset.BitSet)

	// AttackKingPawnSqs 威胁将帅的兵的位置
	AttackKingPawnSqs = make(map[int]*bitset.BitSet)

	// LegalKingMvs 将帅的合法着法位置
	LegalKingMvs = make(map[int]*bitset.BitSet)

	// LegalRedPawnMvs 兵的合法着法位置
	LegalRedPawnMvs [0xBB + 1]*bitset.BitSet
	// LegalBlackPawnMvs 卒的合法着法位置
	LegalBlackPawnMvs [0xBB + 1]*bitset.BitSet
)
View Source
var (
	// RedRookPstValue 红车位置价值
	RedRookPstValue = [...]int{}/* 256 elements not displayed */

	// BlackRookPstValue 黑车位置价值
	BlackRookPstValue = [...]int{}/* 256 elements not displayed */

	// RedCannonPstValue 红炮位置价值
	RedCannonPstValue = [...]int{}/* 256 elements not displayed */

	// BlackCannonPstValue 黑炮位置价值
	BlackCannonPstValue = [...]int{}/* 256 elements not displayed */

	// RedKnightPstValue 红马位置价值
	RedKnightPstValue = [...]int{}/* 256 elements not displayed */

	// BlackKnightPstValue 黑马位置价值
	BlackKnightPstValue = [...]int{}/* 256 elements not displayed */

	// RedBishopPstValue 红相位置价值
	RedBishopPstValue = [...]int{}/* 256 elements not displayed */

	// BlackBishopPstValue 黑象位置价值
	BlackBishopPstValue = [...]int{}/* 256 elements not displayed */

	// RedAdvisorPstValue 红士位置价值
	RedAdvisorPstValue = [...]int{}/* 256 elements not displayed */

	// BlackAdvisorPstValue 黑士位置价值
	BlackAdvisorPstValue = [...]int{}/* 256 elements not displayed */

	// RedKingPstValue 红帅位置价值
	RedKingPstValue = [...]int{}/* 256 elements not displayed */

	// BlackKingPstValue 黑将位置价值
	BlackKingPstValue = [...]int{}/* 256 elements not displayed */

	// RedPawnPstValue 红兵位置价值
	RedPawnPstValue = [...]int{}/* 256 elements not displayed */

	// BlackPawnPstValue 黑兵位置价值
	BlackPawnPstValue = [...]int{}/* 256 elements not displayed */

)

Functions

func File

func File(sq int) int

File 列.

func GetPieceTypeAndSide

func GetPieceTypeAndSide(piece int) (piectType int, isRedSide bool)

func IsInBoard

func IsInBoard(sq uint) bool

IsInBoard 返回 sq 这个位置是否在棋盘内.

func LegalAdvisorMvs

func LegalAdvisorMvs(sq uint) *bitset.BitSet

LegalAdvisorMvs 返回 sq 这个位置士的合法着法位置.

func LegalPawnMvs

func LegalPawnMvs(sq int, isRedSide bool) *bitset.BitSet

LegalPawnMvs 返回 sq 这个位置兵卒的合法着法位置.

func MakePiece

func MakePiece(pieceType int, isRedSide bool) int

MakePiece 返回棋子的数字描述.

func MakeSquare

func MakeSquare(file, rank int) int

func ParsePiece

func ParsePiece(ch rune) int

ParsePiece 解析棋子.

func ParseSquare

func ParseSquare(s string) int

ParseSquare 返回字符表示的 sq. SquareName 的反函数.

func ProbeHash

func ProbeHash(forRed bool, key uint64, depth uint8) (e *transEntry, ok bool)

ProbeHash 置换表检测可取出相应记录时,返回相应记录.

func Rank

func Rank(sq int) int

Rank 行.

func RecordHash

func RecordHash(forRed bool, key uint64, depth uint8, score int16, move Move, bound int8)

func SquareName

func SquareName(sq int) string

SquareName 返回位置的字符表示. 如 sq = 0x22, 返回 "a0". 如 sq = 0x23, 返回 "b0". 如 sq = 0x32, 返回 "a1".

Types

type Engine

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

func (*Engine) GetInfo

func (e *Engine) GetInfo() (name, version, author string)

func (*Engine) Move

func (e *Engine) Move(movDsc string)

func (*Engine) Perft

func (e *Engine) Perft(depth uint) (nodes int)

func (*Engine) Position

func (e *Engine) Position(fen string)

func (*Engine) Prepare

func (e *Engine) Prepare()

func (*Engine) Search

func (e *Engine) Search(depth uint8) (movDesc string, score int)

type Move

type Move int32

Move 前 0-8 位表示 from,第 8-16 位表示 to, 16-20 位表示移动的棋子, 20-24 位表示表示吃掉的棋子.

func StrToMove

func StrToMove(s string) Move

StrToMove m.String() 的反函数.

func (Move) CapturedPiece

func (m Move) CapturedPiece() int

func (Move) From

func (m Move) From() int

func (Move) MovingPiece

func (m Move) MovingPiece() int

MovingPiece 返回移动的棋子.

func (Move) Parse

func (m Move) Parse() (from, to, movingPiece, capturedPiece int)

func (Move) String

func (m Move) String() string

String 返回着法字符表示.

func (Move) To

func (m Move) To() int

type Position

type Position struct {
	Pawns    *bitset.BitSet
	Cannons  *bitset.BitSet
	Rooks    *bitset.BitSet
	Knights  *bitset.BitSet
	Bishops  *bitset.BitSet
	Advisors *bitset.BitSet
	Kings    *bitset.BitSet

	Red   *bitset.BitSet
	Black *bitset.BitSet

	CntRed   uint
	CntBlack uint

	IsRedMove bool
	// Key 当前局面哈希
	Key uint64
	// contains filtered or unexported fields
}

Position 位置信息.

func NewPositionByFen

func NewPositionByFen(fen string) *Position

NewPositionByFen 创建 Position. fen 格式: rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - - 0 1

func (*Position) AllCaptureMoves

func (p *Position) AllCaptureMoves() []int32

func (*Position) AllMoves

func (p *Position) AllMoves() []int32

func (*Position) AllMovesCheckLegal

func (p *Position) AllMovesCheckLegal() []int32

func (*Position) AllPieces

func (p *Position) AllPieces() *bitset.BitSet

AllPieces 返回所有棋子.

func (*Position) ComputeKey

func (p *Position) ComputeKey() uint64

ComputeKey 计算该棋盘的置换表 key,仅初始化时用.

func (*Position) Evaluate

func (p *Position) Evaluate() int

func (*Position) GetKey

func (p *Position) GetKey() uint64

func (*Position) IsAnyPieceBetweenFile

func (p *Position) IsAnyPieceBetweenFile(sq1, sq2 int) bool

IsAnyPieceBetweenFile 判断同一列的两个棋子(sq1, sq2)之间是否还有其他棋子. sq1, sq2 必须是同一列的,即 File(sq1) == File(sq2).

func (*Position) IsAnyPieceBetweenRank

func (p *Position) IsAnyPieceBetweenRank(sq1, sq2 int) bool

IsAnyPieceBetweenRank 判断同一行的两个棋子(sq1, sq2)之间是否还有其他棋子. sq1, sq2 必须是同一行的,即 Rank(sq1) == Rank(sq2).

func (*Position) IsCheck

func (p *Position) IsCheck(isRedCheck bool) bool

IsCheck 返回是否将. isRedCheck = true: 返回红帅是否被将. isRedCheck = false: 返回黑将是否被将.

func (*Position) IsMaximizingPlayerTurn

func (p *Position) IsMaximizingPlayerTurn() bool

func (*Position) IsOnePieceBetweenFile

func (p *Position) IsOnePieceBetweenFile(sq1, sq2 int) bool

IsOnePieceBetweenFile 判断同一列的两个棋子(sq1, sq2)之间是否有且仅有一个棋子. sq1, sq2 必须是同一列的,即 File(sq1) == File(sq2).

func (*Position) IsOnePieceBetweenRank

func (p *Position) IsOnePieceBetweenRank(sq1, sq2 int) bool

IsOnePieceBetweenRank 判断同一行的两个棋子(sq1, sq2)之间是否有且仅有一个棋子. sq1, sq2 必须是同一行的,即 Rank(sq1) == Rank(sq2).

func (*Position) LegalBishopMvs

func (p *Position) LegalBishopMvs(sq uint) *bitset.BitSet

LegalBishopMvs 返回 sq 这个位置象的合法着法位置.

func (*Position) MakeMove

func (p *Position) MakeMove(mov int32)

func (*Position) MakeMoveByDsc

func (p *Position) MakeMoveByDsc(dsc string)

func (*Position) Perft

func (p *Position) Perft(depth uint) (nodes int)

func (*Position) ProbeHash

func (p *Position) ProbeHash(depth uint8) (bestMove int32, score int, hashFlag int8, ok bool)

func (*Position) RecordHash

func (p *Position) RecordHash(depth uint8, score int16, move int32, bound int8)

func (*Position) UnMakeMove

func (p *Position) UnMakeMove(mov int32)

func (*Position) WhatPiece

func (p *Position) WhatPiece(sq uint) int

WhatPiece 返回 sq 位置的棋子类型. XXX 可用一个 256 数组 PiecesSq 存储每个位置的棋子类型提高速度.

Jump to

Keyboard shortcuts

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