func (b *TBoard) NextPseudoLegalMove() bool { for b.CurrentSq < square.BOARD_SIZE { md := MoveTable[b.CurrentPtr] if md.EndPiece { b.CurrentSq++ b.NextSq() } else { cp := b.PieceAtSq(md.To) c := piece.ColorOf(cp) if c == b.GetColorOfTurn() { // own piece b.CurrentPtr = md.NextVector } else if c == piece.NO_COLOR { // empty b.CurrentMove = TMove{b.CurrentSq, md.To, b.CurrentPiece, cp, 0, false} b.CurrentPtr++ return true } else { // capture b.CurrentMove = TMove{b.CurrentSq, md.To, b.CurrentPiece, cp, 0, false} b.CurrentPtr = md.NextVector return true } } } return false }
func (b *TBoard) CalcMaterial() { b.Material[INDEX_OF_WHITE] = 0 b.Material[INDEX_OF_BLACK] = 0 for sq := 0; sq < square.BOARD_SIZE; sq++ { p := b.PieceAtSq(square.TSquare(sq)) c := piece.ColorOf(p) t := piece.TypeOf(p) b.Material[IndexOfColor(c)] += PIECE_VALUES[t] } }
func (pos *TPosition) SetFromFen(fen string) bool { var l = len(fen) if l <= 0 { return false } var ok = true var ptr = 0 var feni = 0 for ; (feni < l) && ok; feni++ { c := fen[feni] if (c >= '1') && (c <= '8') { for fill := 0; fill < int(c-'0'); fill++ { if ptr < square.BOARD_SIZE { pos[ptr] = piece.NO_PIECE ptr++ } } } else if ptr < square.BOARD_SIZE { p := piece.FromFenChar(c) if p != piece.NO_PIECE { pos[ptr] = byte(p) if piece.TypeOf(p) == piece.KING { pos[KINGSPOS_INDEX+IndexOfColor(piece.ColorOf(p))] = byte(ptr) } ptr++ } } ok = (ptr < square.BOARD_SIZE) } if (ptr < square.BOARD_SIZE) || (feni >= (l - 1)) { return false } pos[TURN_INDEX] = piece.WHITE feni++ if fen[feni] == 'b' { pos[TURN_INDEX] = piece.BLACK } pos[DEPTH_INDEX] = 0 return true }
func (b *TBoard) IsSquareColInCheck(sq square.TSquare, c piece.TColor) bool { ksq := b.Pos.GetKingPos(c) for _, pt := range ALL_PIECE_TYPES { test_piece := piece.FromTypeAndColor(pt, piece.InvColorOf(c)) ptr := GetMoveTablePtr(ksq, test_piece) for !MoveTable[ptr].EndPiece { md := MoveTable[ptr] p := b.PieceAtSq(md.To) if p == test_piece { return true } if piece.ColorOf(p) != piece.NO_COLOR { ptr = md.NextVector } else { ptr++ } } } return false }
func (b *TBoard) ColorOfSq(sq square.TSquare) piece.TColor { return piece.ColorOf(piece.TPiece(b.Pos[byte(sq)])) }