Ejemplo n.º 1
0
void generateAndListMoves(board &b) {
	MoveGenerator mg;
	vector<bitmove*> v;

	mg.generate(b, v);

	for (unsigned int i = 0; i < v.size(); i++) {
		cout << *v[i] << ", ";
	}
	cout << endl;
	v.clear();
}
Ejemplo n.º 2
0
int Perft(Position& pos, int depth) {
  int nodes = 0;
 
  if (depth == 0) return 1;

  MoveGenerator generator = MoveGenerator(pos);
  generator.generateMoves();
  auto all_moves = generator.getGeneratedMoves();
  unsigned n_moves = (unsigned) all_moves.size();

  for (unsigned i = 0; i < n_moves; i++) {
    pos.doMove(all_moves[i]);
    nodes += Perft(pos, depth - 1);
    pos.undoMove();
  }
  return nodes;
}
Ejemplo n.º 3
0
int eval_board(const BoardConfig& board, short level, short alpha, short beta, Move* move, char jumps_mandatory)
{
  Move *trial_move, null_move;
  BoardConfig newboard;
  Piece::Type color;
  int maximizing;
  int val;
  MoveGenerator movegen;
				      
  
  maximizing = level % 2;
  if (maximizing)
    color = Color;
  else
    color = (Color & Piece::Red) ? Piece::Black : Piece::Red;
  
  // check right off the bat to see if this is a winning/losing board.
  movegen.prime(board, color, jumps_mandatory);
  if (movegen.getNumberMoves() == 0)
    return (maximizing) ? MY_LOSS : MY_WIN;
  
  // is it time to do a static evaluation?
  if (level > MaxLevel) {
    if (NoHeuristicCont || !jumps_mandatory) {
      return static_eval(board);
    } else {
      if (!movegen.canJump()) {
	MoveGenerator movegen2(board, (color & Piece::Red) ? Piece::Black : Piece::Red, jumps_mandatory);
	if (!movegen2.canJump()) {
	  return static_eval(board);
	}
      }
    }
  }
				      
  // are we at the top level, and only one move is possible?
  if (level == 1 && movegen.getNumberMoves() == 1) {
    // yes, so make that move, and return the magic value that will
    // inform make_move_timed that it doesn\'t have to keep trying.
    *move = *movegen.getNextMove();
    return FORCED_MOVE;
  }
				      
  if (level > MaxLevelSearched)
    MaxLevelSearched = level;
				      
  while ((trial_move = movegen.getNextMove()) && ABcutoff(alpha, beta)) {
    newboard = board.makeMove(*trial_move);
    val = eval_board(newboard, level + 1, alpha, beta, &null_move, jumps_mandatory);
    if (maximizing) {
      if (val > alpha) {
	alpha = val;
	*move = *trial_move;
      }
    } else {
      if (val < beta) {
	beta = val;
	*move = *trial_move;
      }
    }
    delete trial_move;
  }
  
  if (trial_move)
    delete trial_move;
  
  if (maximizing)
    return alpha;
  else
    return beta;
}
Ejemplo n.º 4
0
int Board::countMoves(bool isOpening, QChar color) const
{
	MoveGenerator generator;
	generator.setOpening(isOpening);
	return generator.generate(Board(toString(), color)).size();
}