Beispiel #1
0
void eval_and_sort(
  const evaluator& e, board& b, piece_colour pc, 
  move* movelist, int num_moves)
{
  for (int i = 0; i < num_moves; i++)
  {
    move& m = movelist[i];
    // TODO have the idea of score at a particular depth
    b.do_move(m);
    m.score = e.calc_score(b, pc);
    b.undo_move();
  }

  std::sort(movelist, movelist + num_moves, move_sorter());

#ifdef SHOW_SORTED_MOVES_LIST
  std::cout << "Sorted moves list: ";
  for (int i = 0; i < num_moves; i++)
  {
    move& m = movelist[i];
    std::cout << m << " (" << m.score << ") ";
  }
  std::cout << "\n";
#endif
}
Beispiel #2
0
bool mate_test(board& b, piece_colour pc)
{
  move movelist[200];
  int n = 0;
  gen_moves(b, pc, movelist, n);

  piece_colour opp = flip(pc);
  for (int i = 0; i < n; i++)
  {
    const move& m = movelist[i];
    b.do_move(m);
    bool tk = can_take_opponent_king(b, opp);
    b.undo_move();
    if (!tk)
      return false; // we found a position where king can't be taken
  }
  // No move found where the opponent cannot take the king: this is 
  //  check mate!
  return true;
}