Esempio n. 1
0
void SearcherTest::test_stalemate_data()
{
  QTest::addColumn<ChessBoard>("board");

  QTest::newRow("simple") << parse_fen("7k/5Q2/5K2/6Bp/7P/6P1/8/8 b - - 0 84");
  QTest::newRow("regression 1") << parse_fen("8/6p1/7k/7P/7P/3bp3/4p3/4K3 w - - 0 116");
}
Esempio n. 2
0
void ChessBoardTest::test_finished_data()
{
  QTest::addColumn<ChessBoard>("board");
  QTest::addColumn<bool>("white_won");
  QTest::addColumn<bool>("black_won");
  QTest::addColumn<bool>("draw");

  QTest::newRow("empty") << create_empty_board() << true << true << true;
  QTest::newRow("initial") << create_initial_board() << false << false << false;
  QTest::newRow("normal position") << parse_fen("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -") << false << false << false;
  QTest::newRow("50 moves") << parse_fen("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 50 50") << false << false << true;
  QTest::newRow("white won") << parse_fen("r6r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w - -") << true << false << false;
  QTest::newRow("black won") << parse_fen("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R6R w - -") << false << true << false;
  {
    ChessBoard repetition_board = parse_fen("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w - -");
    UndoInfo dummy;
#ifndef NDEBUG
    const HashState::hash_t hash0 = repetition_board.zobrist_hash();
#endif
    const Move move_white_1 = MoveChecker::complete(Position("a1"), Position("b1"), repetition_board);
    move_white_1.execute(&repetition_board, &dummy);
#ifndef NDEBUG
    const HashState::hash_t hash1 = repetition_board.zobrist_hash();
#endif
    const Move move_black_1 = MoveChecker::complete(Position("a8"), Position("b8"), repetition_board);
    move_black_1.execute(&repetition_board, &dummy);
#ifndef NDEBUG
    const HashState::hash_t hash2 = repetition_board.zobrist_hash();
#endif
    const Move move_white_2 = MoveChecker::complete(Position("b1"), Position("a1"), repetition_board);
    move_white_2.execute(&repetition_board, &dummy);
#ifndef NDEBUG
    const HashState::hash_t hash3 = repetition_board.zobrist_hash();
#endif
    const Move move_black_2 = MoveChecker::complete(Position("b8"), Position("a8"), repetition_board);
    move_black_2.execute(&repetition_board, &dummy);
    assert(hash0 == repetition_board.zobrist_hash());
    move_white_1.execute(&repetition_board, &dummy);
    assert(hash1 == repetition_board.zobrist_hash());
    move_black_1.execute(&repetition_board, &dummy);
    assert(hash2 == repetition_board.zobrist_hash());
    move_white_2.execute(&repetition_board, &dummy);
    assert(hash3 == repetition_board.zobrist_hash());
    move_black_2.execute(&repetition_board, &dummy);
    assert(hash0 == repetition_board.zobrist_hash());
    move_white_1.execute(&repetition_board, &dummy);
    assert(hash1 == repetition_board.zobrist_hash());
    QTest::newRow("repetition") << repetition_board << false << false << true;
  }
}
Esempio n. 3
0
int main(void)
{
	brd_t brd[1], chld_brd[1];
	mv_slct_t slct[1];

	init();

	parse_fen(brd,"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
	//"3r4/p6k/4p1rp/1pp1Pp2/2pN3R/4PQ1R/P2K2PP/1q6 b - - 0 1");
	display_board(brd);

	slct->hash_mv = 0;

	printf("sq(28)="SQ_FMT"\n",SQ_ARGS(28));
	/* Move loop. */
#define MV_SLCT_FN(mv) \
		printf("got move: m=%o f="SQ_FMT" t="SQ_FMT" m=%i c=%i p=%i\n", mv,\
				SQ_ARGS(MV_GET_F(mv)), \
				SQ_ARGS(MV_GET_T(mv)),\
				MV_GET_M(mv),\
				MV_GET_C(mv),\
				MV_GET_P(mv));\

#include "mv_slct.c"

#undef MV_SLCT_FN

	int x;
	for (x = 1; x < 5; x++)
		printf("p[%i]=%i\n", x, perft(brd, x));
}
Esempio n. 4
0
void OncePieceTest::initTestCase()
{
  m_king = &(PieceSet::instance().king());
  m_knight = &(PieceSet::instance().knight());
  m_board = parse_fen("K6N/nK6/6N1/8/7N/4k3/6n1/R3K2R w KQ - 0 1");
  m_king_index = m_king->piece_index();
  m_knight_index = m_knight->piece_index();
}
Esempio n. 5
0
void SearcherTest::test_mate()
{
  m_context.board = parse_fen("7k/6Q1/5K2/6Bp/7P/6P1/8/8 b - - 0 84");
  const SearchResult& result = m_searcher->search(&m_context);
  QVERIFY(result.valid);
  QASSERT_THAT(result.search_depth, Eq(3));
  QVERIFY(result.terminal);
  QASSERT_THAT(result.score, Eq(-24998));
}
Esempio n. 6
0
void SearcherTest::test_mate_in_one()
{
  m_context.board = parse_fen("7k/5Q2/5K2/6Bp/7P/6P1/8/8 w - - 0 84");
  const SearchResult& result = m_searcher->search(&m_context);
  QVERIFY(result.valid);
  QASSERT_THAT(result.search_depth, Eq(3));
  QVERIFY(result.terminal);
  QASSERT_THAT(result.score, Eq(24997));
  QVERIFY(result.has_best_move);
}
int main()
{ 
  int d=0,depth=6;
  Allinit();
  
  S_BOARD board[1];
  S_MOVELIST list[1];

  parse_fen(FEN6,board);
  for(d=1;d<=depth;d++)
  {
    perfttest(d,board);
    printf("\n\n");
  }
  return 0;
}
Esempio n. 8
0
void MoveOrdererTest::test_order_data()
{
  QTest::addColumn<ChessBoard>("board");
  QTest::addColumn<bool>("has_hash_move");
  QTest::addColumn<SearchResult>("entry");
  QTest::addColumn<bool>("has_killer_move");
  QTest::addColumn<Move>("killer_move");
  QTest::addColumn<vector<Move>>("moves");
  QTest::addColumn<vector<Move>>("ordered_moves");

  ChessBoard board = parse_fen("rnb1kbnr/ppp1pppp/1q6/3p4/2P1P3/8/PP1P1PPP/RNBQKBNR b KQkq - 0 1");
  const Move quiet_move = MoveChecker::complete(Position("d5"), Position("d4"), board);
  const Move positive_see_move = MoveChecker::complete(Position("d5"), Position("e4"), board);
  const Move neutral_see_move = MoveChecker::complete(Position("d5"), Position("c4"), board);
  const Move negative_see_move = MoveChecker::complete(Position("b6"), Position("b2"), board);
  const Move killer_move = MoveChecker::complete(Position("a7"), Position("a6"), board);
  {
    const Move hash_move = MoveChecker::complete(Position("a7"), Position("a5"), board);
    vector<Move> moves{quiet_move, positive_see_move, negative_see_move, hash_move, neutral_see_move};
    vector<Move> ordered_moves{hash_move, positive_see_move, neutral_see_move, quiet_move, negative_see_move};
    SearchResult transposition_table_result;
    transposition_table_result.has_best_move = true;
    transposition_table_result.best_move = hash_move;
    transposition_table_result.valid = true;
    QTest::newRow("hash move first")
        << board << true << transposition_table_result
        << false << killer_move << moves << ordered_moves;
  }
  {
    vector<Move> moves{quiet_move, positive_see_move, negative_see_move, neutral_see_move};
    vector<Move> ordered_moves{positive_see_move, neutral_see_move, quiet_move, negative_see_move};
    SearchResult transposition_table_result;
    QTest::newRow("no hash move")
        << board << false << transposition_table_result << false << killer_move << moves << ordered_moves;
  }
  {
    vector<Move> moves{quiet_move, positive_see_move, negative_see_move, neutral_see_move, killer_move};
    vector<Move> ordered_moves{positive_see_move, neutral_see_move, killer_move, quiet_move, negative_see_move};
    SearchResult transposition_table_result;
    QTest::newRow("killer move")
        << board << false << transposition_table_result << true << killer_move << moves << ordered_moves;
  }
}
Esempio n. 9
0
void MoveOrdererTest::test_see_data()
{
  QTest::addColumn<ChessBoard>("board");
  QTest::addColumn<IncompleteMove>("incomplete_move");
  QTest::addColumn<Searcher::score_t>("score");

  QTest::newRow("no capture") << create_initial_board() << IncompleteMove(Position("e2"), Position("e4")) << 0;
  QTest::newRow("simple capture") << parse_fen("rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1")
                                  << IncompleteMove(Position("d5"), Position("e4")) << 100;
  QTest::newRow("guarded capture") << parse_fen("rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 1")
                                   << IncompleteMove(Position("e4"), Position("d5")) << 0;
  QTest::newRow("complex capture") << parse_fen("rnbqkb1r/pp3ppp/2p1pn2/3p3Q/2P1P3/2N5/PP1P1PPP/R1B1KBNR w KQkq - 2 5")
                                   << IncompleteMove(Position("e4"), Position("d5")) << 0;
  QTest::newRow("complex capture win") << parse_fen("rnb1kbnr/ppq2ppp/2p1p3/3p3Q/2P1P3/2N5/PP1P1PPP/R1B1KBNR w KQkq - 2 5")
                                       << IncompleteMove(Position("e4"), Position("d5")) << 100;
  QTest::newRow("xray capture win") << parse_fen("rnbqk1nr/pp2bppp/2p1p3/3p4/2P1P3/2N2Q2/PP1P1PPP/R1B1KBNR w KQkq - 2 5")
                                    << IncompleteMove(Position("e4"), Position("d5")) << 100;
  QTest::newRow("xray through opponent") << parse_fen("rn1qk1nr/pp2bppp/2p1p3/3p4/2P1P3/1bN2Q2/PP1P1PPP/R1B1KBNR w KQkq - 0 1")
                                         << IncompleteMove(Position("e4"), Position("d5")) << 0;
  QTest::newRow("not worth it") << parse_fen("rnbqkbnr/ppp2pp1/3p3p/4p3/5B2/3P1N2/PPP1PPPP/RN1QKB1R w KQkq e6 0 4")
                                << IncompleteMove(Position("f4"), Position("e5")) << -230;
}