Ejemplo n.º 1
0
bool board_is_stalemate(const board_t * board) {

   ASSERT(board_is_ok(board));

   if (board_is_check(board)) return false;
   if (board_can_play(board)) return false;

   return true;
}
Ejemplo n.º 2
0
static void send_board(int extra_move) {

   char fen[256];
   int start, end;
   board_t board[1];
   int pos;
   int move;
   char string[256];

   ASSERT(extra_move==MoveNone||move_is_ok(extra_move));

   ASSERT(!Uci->searching);

   // init

   game_get_board(Game,Uci->board);
   if (extra_move != MoveNone) move_do(Uci->board,extra_move);

   board_to_fen(Uci->board,fen,256);
   my_log("POLYGLOT FEN %s\n",fen);

   ASSERT(board_can_play(Uci->board));

   // more init

   start = 0;
   end = game_pos(Game);
   ASSERT(end>=start);

   // position

   game_get_board(Game,board,start);
   board_to_fen(board,string,256);

   engine_send_queue(Engine,"position");

   if (my_string_equal(string,StartFen)) {
      engine_send_queue(Engine," startpos");
   } else {
      engine_send_queue(Engine," fen %s",string);
   }

   // move list

   if (end > start || extra_move != MoveNone) engine_send_queue(Engine," moves");

   for (pos = start; pos < end; pos++) { // game moves

      move = game_move(Game,pos);

      move_to_can(move,board,string,256);
      engine_send_queue(Engine," %s",string);

      move_do(board,move);
   }

   if (extra_move != MoveNone) { // move to ponder on
      move_to_can(extra_move,board,string,256);
      engine_send_queue(Engine," %s",string);
   }

   // end

   engine_send(Engine,""); // newline
}
Ejemplo n.º 3
0
static int game_comp_status(const game_t * game) {

   int i, n;
   int wb, bb;
   const board_t * board;
   uint64 key;
   int start;

   ASSERT(game!=NULL);

   // init

   board = game->board;

   // mate and stalemate

   if (!board_can_play(board)) {
      if (false) {
      } else if (is_in_check(board,Black)) { // HACK
         return WHITE_MATES;
      } else if (is_in_check(board,White)) { // HACK
         return BLACK_MATES;
      } else {
         return STALEMATE;
      }
   }

   // insufficient material

   if (board->number[WhitePawn12]  == 0
    && board->number[BlackPawn12]  == 0
    && board->number[WhiteQueen12] == 0
    && board->number[BlackQueen12] == 0
    && board->number[WhiteRook12]  == 0
    && board->number[BlackRook12]  == 0) {

      if (board->number[WhiteBishop12]
        + board->number[BlackBishop12]
        + board->number[WhiteKnight12]
        + board->number[BlackKnight12] <= 1) { // KK, KBK and KNK

         return DRAW_MATERIAL;

      } else if (board->number[WhiteBishop12] == 1
              && board->number[BlackBishop12] == 1
              && board->number[WhiteKnight12] == 0
              && board->number[BlackKnight12] == 0) {

         wb = board->list[White][1]; // HACK
         bb = board->list[Black][1]; // HACK

         if (square_colour(wb) == square_colour(bb)) { // KBKB
            return DRAW_MATERIAL;
         }
      }
   }

   // 50-move rule

   if (board->ply_nb >= 100) return DRAW_FIFTY;

   // position repetition

   key = board->key;
   n = 0;

   start = game->pos - board->ply_nb;
   if (start < 0) start = 0;

   for (i = game->pos-4; i >= start; i -= 2) {
      if (game->key[i] == key) {
         if (++n == 2) return DRAW_REPETITION;
      }
   }

   return PLAYING;
}