Ejemplo n.º 1
0
//simple funtion to print the from,to and promoted bit values of the move using fille and ranks
char *PrintMove(int move) {

	static char MvStr[6];
	
	int ff = FileNo[FromSq(move)];
	int rf = RankNo[FromSq(move)];
	int ft = FileNo[ToSq(move)];
	int rt = RankNo[ToSq(move)];
	
	int promoted = Promoted(move);
	
	if(promoted) {
		char pchar = 'q';
		if(IsKnight[promoted]) {
			pchar = 'n';
		} else if(IsRQ[promoted] && !IsBQ[promoted])  {
			pchar = 'r';
		} else if(!IsRQ[promoted] && IsBQ[promoted])  {
			pchar = 'b';
		}
		sprintf(MvStr, "%c%c%c%c%c", ('a'+ff), ('1'+rf), ('a'+ft), ('1'+rt), pchar);
	} else {
		sprintf(MvStr, "%c%c%c%c", ('a'+ff), ('1'+rf), ('a'+ft), ('1'+rt));
	}
	
	return MvStr;
}
Ejemplo n.º 2
0
//this fuction takes in a move in form of files and rank and return the move in integer
int ParseMove(char *ptrChar, BOARD *pos)
{

	if(ptrChar[1] > '8' || ptrChar[1] < '1') return NOMOVE;
    if(ptrChar[3] > '8' || ptrChar[3] < '1') return NOMOVE;
    if(ptrChar[0] > 'h' || ptrChar[0] < 'a') return NOMOVE;
    if(ptrChar[2] > 'h' || ptrChar[2] < 'a') return NOMOVE;

	int f1=(ptrChar[0] - 'a');
	int r1=(ptrChar[1] - '1');
	int f2=(ptrChar[2] - 'a');
	int r2=(ptrChar[3] - '1');
	
    int from = fr2sq(f1, r1);
    int to = fr2sq(f2, r2);	
    
	MOVELIST list[1];
    GenMoves(pos,list);      
    int MoveNum = 0;
	int Move = 0;
	int PromPce = EMPTY;
	
	for(MoveNum = 0; MoveNum < list->Count; ++MoveNum) {	
		Move = list->MoveNum[MoveNum].Move;
		if(FromSq(Move)==from && ToSq(Move)==to) {
			PromPce = Promoted(Move);
			if(PromPce!=EMPTY) {
				if(IsRQ[PromPce] && !IsBQ[PromPce] && ptrChar[4]=='r') {
					return Move;
				} else if(!IsRQ[PromPce] && IsBQ[PromPce] && ptrChar[4]=='b') {
					return Move;
				} else if(IsRQ[PromPce] && IsBQ[PromPce] && ptrChar[4]=='q') {
					return Move;
				} else if(IsKnight[PromPce]&& ptrChar[4]=='n') {
					return Move;
				}
				continue;
			}
			return Move;
		}
    }
    return NOMOVE;	
}
Ejemplo n.º 3
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)