예제 #1
0
void MakeMove(const int& move)
{
#ifdef DEBUG_MODE
	Debugger::searchLine[currentDepth] = move;
#endif
	storeWhiteCastle[currentDepth] = whiteCastle;
	storeBlackCastle[currentDepth] = blackCastle;
	storeEnPassant[currentDepth] = enPassant;
	storeHashKeys[currentDepth] = currentPositionKey;
	storePieceSquareScore[currentDepth] = pieceSquareScore;

	if (enPassant != NoEnPassant)
	{
		currentPositionKey ^= TranspoTable::EnPassantKeys[enPassant];
		enPassant = NoEnPassant;
	}
	currentDepth++;

	repetitionFifty[currentDepth] = repetitionFifty[currentDepth - 1] + 1;

	Square startSquare = Start(move);
	Square endSquare = End(move);
	Piece capturedType = Captured(move);
	Piece promotedType = Promoted(move);
	Piece movedType = Moved(move);

	//General procedures applied to any kind of pieces/moves
	pieceTypes[startSquare] = PieceIndex::NoPiece;
	pieceTypes[endSquare] = movedType;
	Bitboard sourceBit = 1ull << startSquare;
	Bitboard destBit = 1ull << endSquare;
	Bitboard combBit = sourceBit ^ destBit;

	//specific pieces update
	if (whiteToMove)
	{
		switch (movedType)
		{
		case PieceIndex::WhitePawn:
			if (promotedType != PieceIndex::NoPiece)
			{
				pieceBitboards[PieceIndex::WhitePawn] ^= sourceBit;
				whitePawnScore -= PieceScore::PawnScore;

				switch (promotedType)
				{
				case PieceIndex::WhiteQueen:
					pieceBitboards[PieceIndex::WhiteQueen] ^= destBit;
					pieceBitboards[PieceIndex::WhiteRookQueen] ^= destBit;
					pieceBitboards[PieceIndex::WhiteBishopQueen] ^= destBit;
					pieceTypes[endSquare] = PieceIndex::WhiteQueen;
					whitePieceScore += PieceScore::QueenScore;
					pieceSquareScore -= PieceSquareTable[PieceIndex::WhitePawn - 2][startSquare];
					pieceSquareScore += PieceSquareTable[PieceIndex::WhiteQueen - 2][endSquare];
					currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteQueen - 2][endSquare] ^ TranspoTable::ZobristKeys[PieceIndex::WhitePawn - 2][startSquare];
					pawnStructureKey ^= PawnTranspoTable::ZobristKeys[PawnTableWhiteIndex][startSquare];
					break;
				case PieceIndex::WhiteKnight:
					pieceBitboards[PieceIndex::WhiteKnight] ^= destBit;
					pieceTypes[endSquare] = PieceIndex::WhiteKnight;
					whitePieceScore += PieceScore::KnightScore;
					pieceSquareScore -= PieceSquareTable[PieceIndex::WhitePawn - 2][startSquare];
					pieceSquareScore += PieceSquareTable[PieceIndex::WhiteKnight - 2][endSquare];
					currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteKnight - 2][endSquare] ^ TranspoTable::ZobristKeys[PieceIndex::WhitePawn - 2][startSquare];
					pawnStructureKey ^= PawnTranspoTable::ZobristKeys[PawnTableWhiteIndex][startSquare];
					break;
				case PieceIndex::WhiteRook:
					pieceBitboards[PieceIndex::WhiteRook] ^= destBit;
					pieceBitboards[PieceIndex::WhiteRookQueen] ^= destBit;
					pieceTypes[endSquare] = PieceIndex::WhiteRook;
					whitePieceScore += PieceScore::RookScore;
					pieceSquareScore -= PieceSquareTable[PieceIndex::WhitePawn - 2][startSquare];
					pieceSquareScore += PieceSquareTable[PieceIndex::WhiteRook - 2][endSquare];
					currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteRook - 2][endSquare] ^ TranspoTable::ZobristKeys[PieceIndex::WhitePawn - 2][startSquare];
					pawnStructureKey ^= PawnTranspoTable::ZobristKeys[PawnTableWhiteIndex][startSquare];
					break;
				case PieceIndex::WhiteBishop:
					pieceBitboards[PieceIndex::WhiteBishop] ^= destBit;
					pieceBitboards[PieceIndex::WhiteBishopQueen] ^= destBit;
					pieceTypes[endSquare] = PieceIndex::WhiteBishop;
					whitePieceScore += PieceScore::BishopScore;
					pieceSquareScore -= PieceSquareTable[PieceIndex::WhitePawn - 2][startSquare];
					pieceSquareScore += PieceSquareTable[PieceIndex::WhiteBishop - 2][endSquare];
					currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteBishop - 2][endSquare] ^ TranspoTable::ZobristKeys[PieceIndex::WhitePawn - 2][startSquare];
					pawnStructureKey ^= PawnTranspoTable::ZobristKeys[PawnTableWhiteIndex][startSquare];
					break;
				}
			} else
			{
				pieceBitboards[PieceIndex::WhitePawn] ^= combBit;
				currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhitePawn - 2][startSquare] ^ TranspoTable::ZobristKeys[PieceIndex::WhitePawn - 2][endSquare];
				pawnStructureKey ^= PawnTranspoTable::ZobristKeys[PawnTableWhiteIndex][startSquare] ^ PawnTranspoTable::ZobristKeys[PawnTableWhiteIndex][endSquare];
				pieceSquareScore += PieceSquareTable[PieceIndex::WhitePawn - 2][endSquare]
				- PieceSquareTable[PieceIndex::WhitePawn - 2][startSquare];
				if ((endSquare - startSquare) == 16)
				{
					enPassant = endSquare - 8;
					currentPositionKey ^= TranspoTable::EnPassantKeys[enPassant];
				}
			}
			repetitionFifty[currentDepth] = 0;
			break;

		case PieceIndex::WhiteKnight:
			pieceBitboards[PieceIndex::WhiteKnight] ^= combBit;
			currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteKnight - 2][startSquare] ^ TranspoTable::ZobristKeys[PieceIndex::WhiteKnight - 2][endSquare];
			pieceSquareScore += PieceSquareTable[PieceIndex::WhiteKnight - 2][endSquare] - PieceSquareTable[PieceIndex::WhiteKnight - 2][startSquare];
			break;

		case PieceIndex::WhiteBishop:
			pieceBitboards[PieceIndex::WhiteBishop] ^= combBit;
			pieceBitboards[PieceIndex::WhiteBishopQueen] ^= combBit;
			currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteBishop - 2][startSquare] ^ TranspoTable::ZobristKeys[PieceIndex::WhiteBishop - 2][endSquare];
			pieceSquareScore += PieceSquareTable[PieceIndex::WhiteBishop - 2][endSquare] - PieceSquareTable[PieceIndex::WhiteBishop - 2][startSquare];
			break;

		case PieceIndex::WhiteRook:
			pieceBitboards[PieceIndex::WhiteRook] ^= combBit;
			pieceBitboards[PieceIndex::WhiteRookQueen] ^= combBit;
			currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteRook - 2][startSquare] ^ TranspoTable::ZobristKeys[PieceIndex::WhiteRook - 2][endSquare];
			pieceSquareScore += PieceSquareTable[PieceIndex::WhiteRook - 2][endSquare] - PieceSquareTable[PieceIndex::WhiteRook - 2][startSquare];
			if (whiteCastle != NoCastling)
			{
				if (startSquare == Squares::A1 && LongCastle(whiteCastle) != 0)
				{
					currentPositionKey ^= TranspoTable::WhiteLongCastleKey;
					whiteCastle &= 1;
					repetitionFifty[currentDepth] = 0;
				} else if (startSquare == Squares::H1 && ShortCastle(whiteCastle) != 0)
				{
					currentPositionKey ^= TranspoTable::WhiteShortCastleKey;
					whiteCastle &= 2;
					repetitionFifty[currentDepth] = 0;
				}
			}
			break;

		case PieceIndex::WhiteQueen:
			pieceBitboards[PieceIndex::WhiteQueen] ^= combBit;
			pieceBitboards[PieceIndex::WhiteRookQueen] ^= combBit;
			pieceBitboards[PieceIndex::WhiteBishopQueen] ^= combBit;
			currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteQueen - 2][startSquare] ^ TranspoTable::ZobristKeys[PieceIndex::WhiteQueen - 2][endSquare];
			pieceSquareScore += PieceSquareTable[PieceIndex::WhiteQueen - 2][endSquare] - PieceSquareTable[PieceIndex::WhiteQueen - 2][startSquare];
			break;

		case PieceIndex::WhiteKing:
			pieceBitboards[PieceIndex::WhiteKing] ^= combBit;
			currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteKing - 2][startSquare]
			^ TranspoTable::ZobristKeys[PieceIndex::WhiteKing - 2][endSquare];
			pieceSquareScore += PieceSquareTable[PieceIndex::WhiteKing - 2][endSquare] - PieceSquareTable[PieceIndex::WhiteKing - 2][startSquare];

			if (whiteCastle != NoCastling)
			{
				if (endSquare - startSquare == 2)
				{
					pieceBitboards[PieceIndex::WhiteRook] ^= 0xA0l; //0xA0 == '10100000'
					pieceBitboards[PieceIndex::WhiteRookQueen] ^= 0xA0l;
					pieceBitboards[PieceIndex::WhitePieces] ^= 0xA0l;
					pieceBitboards[PieceIndex::AllPieces] ^= 0xA0l;
					pieceTypes[Squares::H1] = PieceIndex::NoPiece;
					pieceTypes[Squares::F1] = PieceIndex::WhiteRook;
					currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteRook - 2][Squares::H1] ^ TranspoTable::ZobristKeys[PieceIndex::WhiteRook - 2][Squares::F1];
					pieceSquareScore += PieceSquareTable[PieceIndex::WhiteRook - 2][Squares::F1] - PieceSquareTable[PieceIndex::WhiteRook - 2][Squares::H1];
				} else if (endSquare - startSquare == -2)
				{
					pieceBitboards[PieceIndex::WhiteRook] ^= 0x9l; //0x9 == '00001001'
					pieceBitboards[PieceIndex::WhiteRookQueen] ^= 0x9l;
					pieceBitboards[PieceIndex::WhitePieces] ^= 0x9l;
					pieceBitboards[PieceIndex::AllPieces] ^= 0x9l;
					pieceTypes[Squares::A1] = PieceIndex::NoPiece;
					pieceTypes[Squares::D1] = PieceIndex::WhiteRook;
					currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::WhiteRook - 2][Squares::A1] ^ TranspoTable::ZobristKeys[PieceIndex::WhiteRook - 2][Squares::D1];
					pieceSquareScore += PieceSquareTable[PieceIndex::WhiteRook - 2][Squares::D1] - PieceSquareTable[PieceIndex::WhiteRook - 2][Squares::A1];
				}
				if (LongCastle(whiteCastle) != 0)
				{
					currentPositionKey ^= TranspoTable::WhiteLongCastleKey;
				}
				if (ShortCastle(whiteCastle) != 0)
				{
					currentPositionKey ^= TranspoTable::WhiteShortCastleKey;
				}
				whiteCastle = NoCastling;
				repetitionFifty[currentDepth] = 0;
			}
			break;
		}

		pieceBitboards[PieceIndex::WhitePieces] ^= combBit;
		pieceBitboards[PieceIndex::AllPieces] ^= combBit;

		if (capturedType != PieceIndex::NoPiece)
		{
			switch (capturedType)
			{
			case PieceIndex::BlackPawn:
				pieceBitboards[PieceIndex::BlackPawn] ^= destBit;
				pieceBitboards[PieceIndex::BlackPieces] ^= destBit;
				pieceBitboards[PieceIndex::AllPieces] ^= destBit;
				blackPawnScore -= PieceScore::PawnScore;
				pieceSquareScore += PieceSquareTable[PieceIndex::BlackPawn - 2][endSquare];
				currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::BlackPawn - 2][endSquare];
				pawnStructureKey ^= PawnTranspoTable::ZobristKeys[PawnTableBlackIndex][endSquare];
				break;

			case PieceIndex::BlackKnight:
				pieceBitboards[PieceIndex::BlackKnight] ^= destBit;
				pieceBitboards[PieceIndex::BlackPieces] ^= destBit;
				pieceBitboards[PieceIndex::AllPieces] ^= destBit;
				blackPieceScore -= PieceScore::KnightScore;
				pieceSquareScore += PieceSquareTable[PieceIndex::BlackKnight - 2][endSquare];
				currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::BlackKnight - 2][endSquare];
				break;

			case PieceIndex::BlackBishop:
				pieceBitboards[PieceIndex::BlackBishop] ^= destBit;
				pieceBitboards[PieceIndex::BlackBishopQueen] ^= destBit;
				pieceBitboards[PieceIndex::BlackPieces] ^= destBit;
				pieceBitboards[PieceIndex::AllPieces] ^= destBit;
				blackPieceScore -= PieceScore::BishopScore;
				pieceSquareScore += PieceSquareTable[PieceIndex::BlackBishop - 2][endSquare];
				currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::BlackBishop - 2][endSquare];
				break;

			case PieceIndex::BlackRook:
				pieceBitboards[PieceIndex::BlackRook] ^= destBit;
				pieceBitboards[PieceIndex::BlackRookQueen] ^= destBit;
				pieceBitboards[PieceIndex::BlackPieces] ^= destBit;
				pieceBitboards[PieceIndex::AllPieces] ^= destBit;
				blackPieceScore -= PieceScore::RookScore;
				pieceSquareScore += PieceSquareTable[PieceIndex::BlackRook - 2][endSquare];
				currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::BlackRook - 2][endSquare];
				if (blackCastle != NoCastling)
				{
					if (endSquare == Squares::A8 && LongCastle(blackCastle) != 0)
					{
						currentPositionKey ^= TranspoTable::BlackLongCastleKey;
						blackCastle &= 1;
					} else if (endSquare == Squares::H8 && ShortCastle(blackCastle) != 0)
					{
						currentPositionKey ^= TranspoTable::BlackShortCastleKey;
						blackCastle &= 2;
					}
				}
				break;

			case PieceIndex::BlackQueen:
				pieceBitboards[PieceIndex::BlackQueen] ^= destBit;
				pieceBitboards[PieceIndex::BlackRookQueen] ^= destBit;
				pieceBitboards[PieceIndex::BlackBishopQueen] ^= destBit;
				pieceBitboards[PieceIndex::BlackPieces] ^= destBit;
				pieceBitboards[PieceIndex::AllPieces] ^= destBit;
				blackPieceScore -= PieceScore::QueenScore;
				pieceSquareScore += PieceSquareTable[PieceIndex::BlackQueen - 2][endSquare];
				currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::BlackQueen - 2][endSquare];
				break;

			case PieceIndex::EnPassant:
				Bitboard enPassantBit = destBit >> 8;
				Square enPassantSquare = endSquare - 8;
				pieceBitboards[PieceIndex::BlackPawn] ^= enPassantBit;
				pieceBitboards[PieceIndex::BlackPieces] ^= enPassantBit;
				pieceBitboards[PieceIndex::AllPieces] ^= enPassantBit;
				pieceTypes[enPassantSquare] = PieceIndex::NoPiece;
				blackPawnScore -= PieceScore::PawnScore;
				pieceSquareScore += PieceSquareTable[PieceIndex::BlackPawn - 2][enPassantSquare];
				currentPositionKey ^= TranspoTable::ZobristKeys[PieceIndex::BlackPawn - 2][enPassantSquare];
				pawnStructureKey ^= PawnTranspoTable::ZobristKeys[PawnTableBlackIndex][enPassantSquare];
				break;
			}
			repetitionFifty[currentDepth] = 0;
		}
	} else
	{
		switch (movedType)
예제 #2
0
  uint64_t rsliders =
      Rooks(white) | Rooks(black) | Queens(white) | Queens(black);
  int attacked_piece, piece, nc = 1, see_list[32];
  int source = From(move), target = To(move);

/*
 ************************************************************
 *                                                          *
 *  Determine which squares attack <target> for each side.  *
 *  initialize by placing the piece on <target> first in    *
 *  the list as it is being captured to start things off.   *
 *                                                          *
 ************************************************************
 */
  attacks = AttacksTo(tree, target);
  attacked_piece = pcval[Captured(move)];
/*
 ************************************************************
 *                                                          *
 *  The first piece to capture on <target> is the piece     *
 *  standing on <source>.                                   *
 *                                                          *
 ************************************************************
 */
  wtm = Flip(wtm);
  see_list[0] = attacked_piece;
  piece = Piece(move);
  attacked_piece = pcval[piece];
  Clear(source, toccupied);
  if (piece & 1)
    attacks |= BishopAttacks(target, toccupied) & bsliders;