Documentation ¶
Index ¶
- Constants
- Variables
- func File(sq int) int
- func GetPieceTypeAndSide(piece int) (piectType int, isRedSide bool)
- func IsInBoard(sq uint) bool
- func LegalAdvisorMvs(sq uint) *bitset.BitSet
- func LegalPawnMvs(sq int, isRedSide bool) *bitset.BitSet
- func MakePiece(pieceType int, isRedSide bool) int
- func MakeSquare(file, rank int) int
- func ParsePiece(ch rune) int
- func ParseSquare(s string) int
- func ProbeHash(forRed bool, key uint64, depth uint8) (e *transEntry, ok bool)
- func Rank(sq int) int
- func RecordHash(forRed bool, key uint64, depth uint8, score int16, move Move, bound int8)
- func SquareName(sq int) string
- type Engine
- type Move
- type Position
- func (p *Position) AllCaptureMoves() []int32
- func (p *Position) AllMoves() []int32
- func (p *Position) AllMovesCheckLegal() []int32
- func (p *Position) AllPieces() *bitset.BitSet
- func (p *Position) ComputeKey() uint64
- func (p *Position) Evaluate() int
- func (p *Position) GetKey() uint64
- func (p *Position) IsAnyPieceBetweenFile(sq1, sq2 int) bool
- func (p *Position) IsAnyPieceBetweenRank(sq1, sq2 int) bool
- func (p *Position) IsCheck(isRedCheck bool) bool
- func (p *Position) IsMaximizingPlayerTurn() bool
- func (p *Position) IsOnePieceBetweenFile(sq1, sq2 int) bool
- func (p *Position) IsOnePieceBetweenRank(sq1, sq2 int) bool
- func (p *Position) LegalBishopMvs(sq uint) *bitset.BitSet
- func (p *Position) MakeMove(mov int32)
- func (p *Position) MakeMoveByDsc(dsc string)
- func (p *Position) Perft(depth uint) (nodes int)
- func (p *Position) ProbeHash(depth uint8) (bestMove int32, score int, hashFlag int8, ok bool)
- func (p *Position) RecordHash(depth uint8, score int16, move int32, bound int8)
- func (p *Position) UnMakeMove(mov int32)
- func (p *Position) WhatPiece(sq uint) int
Constants ¶
const ( // Empty 无 Empty int = iota // King 帅 King // Rook 车 Rook // Knight 马 Knight // Cannon 炮 Cannon // Advisor 士 Advisor // Bishop 象 Bishop // Pawn 兵 Pawn )
const MoveEmpty = Move(0)
const (
SquareNone = -1
)
Variables ¶
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 )
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 GetPieceTypeAndSide ¶
func LegalAdvisorMvs ¶
LegalAdvisorMvs 返回 sq 这个位置士的合法着法位置.
func LegalPawnMvs ¶
LegalPawnMvs 返回 sq 这个位置兵卒的合法着法位置.
func MakeSquare ¶
func RecordHash ¶
func SquareName ¶
SquareName 返回位置的字符表示. 如 sq = 0x22, 返回 "a0". 如 sq = 0x23, 返回 "b0". 如 sq = 0x32, 返回 "a1".
Types ¶
type Move ¶
type Move int32
Move 前 0-8 位表示 from,第 8-16 位表示 to, 16-20 位表示移动的棋子, 20-24 位表示表示吃掉的棋子.
func (Move) CapturedPiece ¶
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 ¶
NewPositionByFen 创建 Position. fen 格式: rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - - 0 1
func (*Position) AllCaptureMoves ¶
func (*Position) AllMovesCheckLegal ¶
func (*Position) ComputeKey ¶
ComputeKey 计算该棋盘的置换表 key,仅初始化时用.
func (*Position) IsAnyPieceBetweenFile ¶
IsAnyPieceBetweenFile 判断同一列的两个棋子(sq1, sq2)之间是否还有其他棋子. sq1, sq2 必须是同一列的,即 File(sq1) == File(sq2).
func (*Position) IsAnyPieceBetweenRank ¶
IsAnyPieceBetweenRank 判断同一行的两个棋子(sq1, sq2)之间是否还有其他棋子. sq1, sq2 必须是同一行的,即 Rank(sq1) == Rank(sq2).
func (*Position) IsCheck ¶
IsCheck 返回是否将. isRedCheck = true: 返回红帅是否被将. isRedCheck = false: 返回黑将是否被将.
func (*Position) IsMaximizingPlayerTurn ¶
func (*Position) IsOnePieceBetweenFile ¶
IsOnePieceBetweenFile 判断同一列的两个棋子(sq1, sq2)之间是否有且仅有一个棋子. sq1, sq2 必须是同一列的,即 File(sq1) == File(sq2).
func (*Position) IsOnePieceBetweenRank ¶
IsOnePieceBetweenRank 判断同一行的两个棋子(sq1, sq2)之间是否有且仅有一个棋子. sq1, sq2 必须是同一行的,即 Rank(sq1) == Rank(sq2).
func (*Position) LegalBishopMvs ¶
LegalBishopMvs 返回 sq 这个位置象的合法着法位置.