コード例 #1
0
ファイル: board.go プロジェクト: goracingkingsengine/gorke
func (b *TBoard) EvalCol(c piece.TColor) int {
	eval := b.Material[IndexOfColor(c)]
	ksq := b.GetKingPos(c)
	ksqr := int(square.BOARD_HEIGHTL - square.RankOf(ksq))
	eval += ksqr * KING_ADVANCE_VALUE
	return eval
}
コード例 #2
0
ファイル: board.go プロジェクト: goracingkingsengine/gorke
func InitMoveTable() {
	ptr := 0
	for _, pt := range ALL_PIECE_TYPES {
		for sq := 0; sq < square.BOARD_SIZE; sq++ {

			MoveTablePtrs[TMoveTableKey{square.TSquare(sq), piece.FromTypeAndColor(piece.TPieceType(pt), piece.BLACK)}] = ptr
			MoveTablePtrs[TMoveTableKey{square.TSquare(sq), piece.FromTypeAndColor(piece.TPieceType(pt), piece.WHITE)}] = ptr

			for df := -2; df <= 2; df++ {
				for dr := -2; dr <= 2; dr++ {
					vector_ok := false
					dfabs := math.Abs(float64(df))
					drabs := math.Abs(float64(dr))
					prodabs := dfabs * drabs
					sumabs := dfabs + drabs
					if (pt & piece.IS_JUMPING) != 0 {
						vector_ok = vector_ok || (prodabs == 2)
					}
					if (pt & piece.IS_STRAIGHT) != 0 {
						vector_ok = vector_ok || (sumabs == 1)
					}
					if (pt & piece.IS_DIAGONAL) != 0 {
						vector_ok = vector_ok || (prodabs == 1)
					}
					if vector_ok {
						ok := true
						f := int(square.FileOf(square.TSquare(sq)))
						r := int(square.RankOf(square.TSquare(sq)))
						vector_start := ptr
						for ok {
							f += df
							r += dr
							if square.FileRankOk(f, r) {
								tsq := square.FromFileRank(square.TFile(f), square.TRank(r))
								MoveTable[ptr].To = tsq
								MoveTable[ptr].EndPiece = false
								ptr++
							} else {
								ok = false
							}
							if (pt & piece.IS_SLIDING) == 0 {
								ok = false
							}
						}
						for vector_next_ptr := vector_start; vector_next_ptr < ptr; vector_next_ptr++ {
							MoveTable[vector_next_ptr].NextVector = ptr
						}
					}
				}
			}

			MoveTable[ptr].EndPiece = true
			ptr++
		}
	}
}
コード例 #3
0
ファイル: board.go プロジェクト: goracingkingsengine/gorke
func (b *TBoard) NextLegalMove() bool {
	if b.BlackKingOnBaseRank() {
		return false
	}
	wb := b.WhiteKingOnBaseRank()
	if wb && b.IsWhiteTurn() {
		return false
	}
	if b.HasBestMove {
		if !b.BestMoveDone {
			b.CurrentMove = b.BestMove
			b.BestMoveDone = true
			return true
		}
	}
	for b.NextPseudoLegalMove() {
		b.MakeMove(b.CurrentMove)
		incheck := b.IsInCheck()
		oppincheck := b.IsOppInCheck()
		blackmated := (wb && (!b.BlackKingOnBaseRank()))
		b.UnMakeMove(b.CurrentMove)
		ok := (!incheck) && (!oppincheck) && (!blackmated)
		if !ok {
			//fmt.Printf("move thrown out for check %s\n",b.CurrentMove.ToAlgeb())
		}
		if ok {
			if b.BestMoveDone || (b.CurrentMove != b.BestMove) {
				// move is ok
				if piece.TypeOf(b.CurrentMove.Piece) == piece.KING {
					if square.RankOf(b.CurrentMove.To) > square.RankOf(b.CurrentMove.From) {
						b.CurrentMove.IsForwardKingMove = true
					}
				}
				return true
			}
		}
	}
	return false
}
コード例 #4
0
ファイル: board.go プロジェクト: goracingkingsengine/gorke
func (b *TBoard) KingOnBaseRank(c piece.TColor) bool {
	return (square.RankOf(b.GetKingPos(c)) == 0)
}