Пример #1
0
bool
threefold_repetition (Game *g)
{
  if (g->current < 6) // Minimum moves to get a threefold repetition
    return FALSE;
  char placement[65];
  char turn;
  char *fen, *castling, *ep;
  char* s[g->current + 1];
  s[0] = (char *) malloc (80);
  strcpy (s[0], "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -");
  int i, j;
  bool found = FALSE;
  for (i = 0; i < g->current; i++)
    {
      fen = to_fen (g->boards[i]);
      for (j = 0; fen[j] != ' '; j++)
        placement[j] = fen[j];
      placement[j] = '\0';
      s[i+1] = (char *) malloc (80);
      turn = g->boards[i]->active_color ? 'b' : 'w';
      castling = castling_to_s (g->boards[i]->castling);
      ep = en_passant_to_s (g->boards[i]->en_passant);
      sprintf (s[i+1], "%s %c %s %s", placement, turn, castling, ep);
      free (fen);
      free (castling);
      free (ep);
    }
  qsort (s, g->current + 1, sizeof (char *), compare);
  for (i = 0; i < g->current - 1; i++)
    {
      if (strcmp (s[i], s[i+1]) == 0 && strcmp (s[i], s[i+2]) == 0)
        {
          found = TRUE;
          break;
        }
      free (s[i]);
    }
  free (s[g->current]);
  free (s[g->current-1]);
  return found;
}
Пример #2
0
Value Position::evaluate(const Color us, SearchStack* ss)
{
	int score = 0;

#if defined(EVAL_DIFF)
    // null move
    if (ss->staticEvalRaw != INT_MAX) {
        score = int(ss->staticEvalRaw);
    }
    else

	if (calc_difference(ss)) {
        score = int(ss->staticEvalRaw);
        //ehash_store(st->key, HAND_B, score);
    } else
#endif

    {
        // 普通に評価値を計算
        score = evaluate_raw_body();
#if defined(EVAL_DIFF)
        ss->staticEvalRaw = Value(score);
#endif
    }

#if defined(_DEBUG)
    if (score != evaluate_raw_correct()) {
        std::cout << "Evaluate Value Error !!!" << std::endl;
        std::cout << to_fen() << std::endl;
        exit(-1);
    }
#endif

    score /= FV_SCALE;
    score += MATERIAL;
    score = (us == BLACK) ? score : -score;
    return Value(score);
}
Пример #3
0
///////////////////////////////////
// MAIN (only for internal test) //
///////////////////////////////////
int
main ()
{
  // Valgrind run
  init_chess_library ();
  int i, from, to;

  for (i = 0; i < 1000; i++)
    {
      Game *g = init_game ();
      Board *board;
      char *fen;

      // 1. e4 a6 2. Bc4 a5 3. Qh5 a4 4. Qxf7#
      board = current_board (g);
      get_coord (board, 'P', "e", "e4", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (board);
      free (fen);

      board = current_board (g);
      get_coord (board, 'P', "a", "a6", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'B', "", "c4", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'P', "a", "a5", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'Q', "", "h5", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'P', "a", "a4", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      board = current_board (g);
      get_coord (board, 'Q', "", "f7", 0, &from, &to);
      pseudo_legal_move (board, from, to);
      apply_move (g, from, to, 0);
      fen = to_fen (current_board (g));
      free (fen);

      free_game (g);
    }
  return 0;
}