コード例 #1
0
ファイル: data.cpp プロジェクト: JERUKA9/lucaschess
void info()
{
 
       //  your playground... display variables - meant for testing/verification purposes only
       std::cout << std::endl << "============ info start ==============" << std::endl;
       std::cout << "size of board, in bytes   = " << sizeof(board) << std::endl;
       std::cout << "Material value            = " << board.Material << std::endl;
       std::cout << "White castling rights     = " << int(board.castleWhite) << std::endl;
       std::cout << "Black castling rights     = " << int(board.castleBlack) << std::endl;
       std::cout << "En-passant square         = " << board.epSquare << std::endl;
       std::cout << "Fifty move count          = " << board.fiftyMove << std::endl;
 
       std::cout << "bitCnt of white pawns     = " << bitCnt(board.whitePawns) << std::endl;
       std::cout << std::endl << "bitmap of blackKnights | board.whitePawns:" << std::endl;
       displayBitmap(board.blackKnights | board.whitePawns);
       std::cout << "============ info end ================" << std::endl << std::endl;
 
       return;
}
コード例 #2
0
ファイル: search.cpp プロジェクト: lennonc/Chess
BOOLTYPE Board::isEndOfgame(int &legalmoves, Move &singlemove)
{
  // Checks if the current position is end-of-game due to:
  // checkmate, stalemate, 50-move rule, or insufficient material
  
  int whiteknights, whitebishops, whiterooks, whitequeens, whitetotalmat;
  int blackknights, blackbishops, blackrooks, blackqueens, blacktotalmat;
  
  // are we checkmating the other side?
  int i;
  if (isOtherKingAttacked())
  {
    if (nextMove) std::cout << "1-0 {Black mates}" << std::endl;
    else std::cout << "1-0 {White mates}" << std::endl;
    return true;
  }
  
  // how many legal moves do we have?
  legalmoves = 0;
  moveBufLen[0] = 0;
  moveBufLen[1] = movegen(moveBufLen[0]);
  for (i = moveBufLen[0]; i < moveBufLen[1]; i++)
  {
    makeMove(moveBuffer[i]);
    if (!isOtherKingAttacked())
    {
      legalmoves++;
      singlemove = moveBuffer[i];
    }
    unmakeMove(moveBuffer[i]);
  }
  
  // checkmate or stalemate?
  if (!legalmoves)
  {
    if (isOwnKingAttacked())
    {
      if (nextMove) std::cout << "1-0 {White mates}" << std::endl;
      else std::cout << "1-0 {Black mates}" << std::endl;
    }
    else std::cout << "1/2-1/2 {stalemate}" << std::endl;
    return true;
  }
  
  // draw due to insufficient material:
  if (!whitePawns && !blackPawns)
  {
    whiteknights = bitCnt(whiteKnights);
    whitebishops = bitCnt(whiteBishops);
    whiterooks = bitCnt(whiteRooks);
    whitequeens = bitCnt(whiteQueens);
    whitetotalmat = 3 * whiteknights + 3 * whitebishops + 5 * whiterooks + 10 * whitequeens;
    blackknights = bitCnt(blackKnights);
    blackbishops = bitCnt(blackBishops);
    blackrooks = bitCnt(blackRooks);
    blackqueens = bitCnt(blackQueens);
    blacktotalmat = 3 * blackknights + 3 * blackbishops + 5 * blackrooks + 10 * blackqueens;
    
    // king versus king:
    if ((whitetotalmat == 0) && (blacktotalmat == 0))
    {
      std::cout << "1/2-1/2 {material}" << std::endl;
      return true;
    }
    
    // king and knight versus king:
    if (((whitetotalmat == 3) && (whiteknights == 1) && (blacktotalmat == 0)) ||
        ((blacktotalmat == 3) && (blackknights == 1) && (whitetotalmat == 0)))
    {
      std::cout << "1/2-1/2 {material}" << std::endl;
      return true;
    }
    
    // 2 kings with one or more bishops, all bishops on the same colour:
    if ((whitebishops + blackbishops) > 0)
    {
      if ((whiteknights == 0) && (whiterooks == 0) && (whitequeens == 0) &&
          (blackknights == 0) && (blackrooks == 0) && (blackqueens == 0))
      {
        if (!((whiteBishops | blackBishops) & WHITE_SQUARES) ||
            !((whiteBishops | blackBishops) & BLACK_SQUARES))
        {
          std::cout << "1/2-1/2 {material}" << std::endl;
          return true;
        }
      }
    }
  }
  
  // draw due to repetition:
  if (repetitionCount() >= 3)
  {
    std::cout << "1/2-1/2 {repetition}" << std::endl;
    return true;
    
  }
  
  // draw due to 50 move rule:
  if (fiftyMove >= 100)
  {
    std::cout << "1/2-1/2 {50-move rule}" << std::endl;
    return true;
  }
  
  return false;
}
コード例 #3
0
ファイル: board.cpp プロジェクト: JERUKA9/lucaschess
void Board::initFromSquares(int input[64], unsigned char next, int fiftyM, int castleW, int castleB, int epSq)
{
	// sets up the board variables according to the information found in
	// the input[64] array
	// All board & game initializations are done through this function (including readfen and setup).
 
	int i;
 
	// bitboards
	whiteKing    = 0;
	whiteQueens  = 0;
	whiteRooks   = 0;
	whiteBishops = 0;
	whiteKnights = 0;
	whitePawns   = 0;
	blackKing    = 0;
	blackQueens  = 0;
	blackRooks   = 0;
	blackBishops = 0;
	blackKnights = 0;
	blackPawns   = 0;
	whitePieces  = 0;
	blackPieces  = 0;
	occupiedSquares = 0;
	hashkey = 0;

	// populate the 12 bitboard:
	for (i = 0; i < 64; i++)
	{
		square[i] = input[i];
		if (square[i] == WHITE_KING) 
		{  
			whiteKing    = whiteKing | BITSET[i]; 
			hashkey     ^= KEY.keys[i][WHITE_KING];  
		}
		if (square[i] == WHITE_QUEEN)
		{
			whiteQueens  = whiteQueens  | BITSET[i];
			hashkey     ^= KEY.keys[i][WHITE_QUEEN];  		
		}
		if (square[i] == WHITE_ROOK)
		{
			whiteRooks   = whiteRooks   | BITSET[i];
			hashkey     ^= KEY.keys[i][WHITE_ROOK];  		
		}
		if (square[i] == WHITE_BISHOP)
		{
			whiteBishops = whiteBishops | BITSET[i];
			hashkey     ^= KEY.keys[i][WHITE_BISHOP];  		
		}
		if (square[i] == WHITE_KNIGHT) 
		{
			whiteKnights = whiteKnights | BITSET[i];
			hashkey     ^= KEY.keys[i][WHITE_KNIGHT];  		
		}
		if (square[i] == WHITE_PAWN)   
		{
			whitePawns   = whitePawns   | BITSET[i];
			hashkey     ^= KEY.keys[i][WHITE_PAWN];  		
		}
		if (square[i] == BLACK_KING)   
		{
			blackKing    = blackKing    | BITSET[i];
			hashkey     ^= KEY.keys[i][BLACK_KING];  		
		}
		if (square[i] == BLACK_QUEEN)  
		{
			blackQueens  = blackQueens  | BITSET[i];
			hashkey     ^= KEY.keys[i][BLACK_QUEEN];  		
		}
		if (square[i] == BLACK_ROOK)   
		{
			blackRooks   = blackRooks   | BITSET[i];
			hashkey     ^= KEY.keys[i][BLACK_ROOK];  		
		}
		if (square[i] == BLACK_BISHOP) 
		{
			blackBishops = blackBishops | BITSET[i];
			hashkey     ^= KEY.keys[i][BLACK_BISHOP];  		
		}
		if (square[i] == BLACK_KNIGHT) 
		{
			blackKnights = blackKnights | BITSET[i];
			hashkey     ^= KEY.keys[i][BLACK_KNIGHT];  		
		}
		if (square[i] == BLACK_PAWN)   
		{
			blackPawns   = blackPawns   | BITSET[i];
			hashkey     ^= KEY.keys[i][BLACK_PAWN];  		
		}
	}
 
	whitePieces = whiteKing | whiteQueens | whiteRooks | whiteBishops | whiteKnights | whitePawns;
	blackPieces = blackKing | blackQueens | blackRooks | blackBishops | blackKnights | blackPawns;
	occupiedSquares = whitePieces | blackPieces;
 
	nextMove = next;

	castleWhite = castleW;
	castleBlack = castleB;
	epSquare = epSq;
	fiftyMove = fiftyM;

	if (castleWhite & CANCASTLEOO)  hashkey ^= KEY.wk;
	if (castleWhite & CANCASTLEOOO) hashkey ^= KEY.wq;
	if (castleBlack & CANCASTLEOO)  hashkey ^= KEY.bk;
	if (castleBlack & CANCASTLEOOO) hashkey ^= KEY.bq;
	if (nextMove) hashkey ^= KEY.side;
	if (epSq) hashkey ^= KEY.ep[epSq];
 
	totalWhitePawns = bitCnt(whitePawns) * PAWN_VALUE;
	totalBlackPawns = bitCnt(blackPawns) * PAWN_VALUE;
	totalWhitePieces = 	bitCnt(whiteKnights) * KNIGHT_VALUE + bitCnt(whiteBishops) * BISHOP_VALUE +
							bitCnt(whiteRooks) * ROOK_VALUE + bitCnt(whiteQueens) * QUEEN_VALUE;
	totalBlackPieces = 	bitCnt(blackKnights) * KNIGHT_VALUE + bitCnt(blackBishops) * BISHOP_VALUE +
							bitCnt(blackRooks) * ROOK_VALUE + bitCnt(blackQueens) * QUEEN_VALUE;
	Material  = totalWhitePawns + totalWhitePieces - totalBlackPawns - totalBlackPieces;
 
	endOfGame = 0;
	endOfSearch = 0;
	for (i = 0; i < MAX_PLY; i++) 
	{
		moveBufLen[i] = 0;
		triangularLength[i] = 0;
	}
	inodes = 0;
	return;
}