void MoveGeneratorTest::test_move() { CPPUNIT_ASSERT(test_board("res/testqueen.txt") == 32); CPPUNIT_ASSERT(test_board("res/testking.txt") == 8); CPPUNIT_ASSERT(test_board("res/startboard.txt") == 20); CPPUNIT_ASSERT(test_board("res/startboard.txt", false) == 20); CPPUNIT_ASSERT(test_board("res/testcastling.txt") == 26); CPPUNIT_ASSERT(test_board("res/testcastlingblock.txt") == 23); CPPUNIT_ASSERT(test_board("res/testcastlingcheckblock.txt") == 20); CPPUNIT_ASSERT(test_board("res/testblackpieces.txt", false) == 6); CPPUNIT_ASSERT(test_board("res/pawntest.txt", true) == 21); CPPUNIT_ASSERT(test_board("res/testcheckmate.txt") == 0); }
TEST(gogame_move_check, repeate_moves_history) { uint8_t board_size = 5; GoBoard test_board(board_size); test_board.board[1] = {0, get_mask(0), 0, get_mask(0), 0}; test_board.board[2] = {0, get_mask(1), get_mask(0), get_mask(1), 0}; test_board.board[3][2] = get_mask(1); GoGame test_game(test_board); // Make first move GoMove test_move1(test_game.get_board(), XYCoordinate(0, 2)); test_move1.check_move(0); test_game.make_move(test_move1, 0); // Make capture GoMove test_move2(test_game.get_board(), XYCoordinate(2, 1)); test_move2.check_move(1); test_game.make_move(test_move2, 1); // Attempt to make second capture which would reset board to a prior state GoMove test_move3(test_game.get_board(), XYCoordinate(2, 2)); test_move3.check_move(0); // Check move is in move history EXPECT_EQ(true, test_game.check_move_history(test_move3)); }
static void test_heuri(int n, bool disp_sorted) { int i = 0; std::vector<t_test_struct> test({ {"boards/test_h_line", "Test with 5 H stone", Board::Point::BLACK, 100060}, {"boards/test_V_line", "Test with 5 V stone", Board::Point::BLACK, 100060}, {"boards/test_d1_line", "Test with 5 DIAG1 stone", Board::Point::BLACK, 100060}, {"boards/test_d2_line", "Test with 5 DIAG2 stone", Board::Point::BLACK, 100060}, {"boards/test_4_stone", "Test with 4 DIAG2 stone", Board::Point::BLACK, 320}, {"boards/test_4_stone_blocked", "Test with 4 DIAG2 stone blocked on each border", Board::Point::BLACK, 16}, {"boards/test_4_stone_blocked_wall", "Test with 4 DIAG2 stone blocked on each border", Board::Point::BLACK, 24}, {"boards/test_4_stone_with_hole", "Test with 4 DIAG2 stone with hole in the middle", Board::Point::BLACK, 300}, {"boards/test_3_stone", "Test with 3 DIAG1 stone", Board::Point::BLACK, 116}, {"boards/test_3_stone_one_blocked", "Test with 3 DIAG1 stone", Board::Point::BLACK, 88}, {"boards/test_3_stone_two_blocked", "Test with 3 DIAG1 stone", Board::Point::BLACK, 4}, {"boards/test_3_stone_with_hole", "Test with 3 DIAG1 stone", Board::Point::BLACK, 100}, {"boards/test_2_stone", "Test with 2 H stone", Board::Point::BLACK, 40}, {"boards/test_2_stone_space", "Test with 2 H stone with hole", Board::Point::BLACK, 24}, {"boards/test_1_stone", "Test with 1 H stone", Board::Point::BLACK, 16}, {"boards/toto", "TOTO", Board::Point::BLACK, 32}, {"boards/toto2", "TOTO", Board::Point::BLACK, 32}, {"boards/toto3", "TOTO", Board::Point::BLACK, 32}, {"boards/toto4", "TOTO", Board::Point::BLACK, 32}, {"boards/toto5", "TOTO", Board::Point::BLACK, 32}, {"boards/toto6", "TOTO", Board::Point::BLACK, 32}, {"", "", Board::Point::EMPTY, MAGIC, false}, }); if (n >= 0) { std::cout << "HERE" << std::endl; test_board(test[n], true); return ; } while (test[i].res != MAGIC) { std::cout << "Testing:" << i << std::endl; test_board(test[i], false); i++; } displaySuccess(test); if (disp_sorted) displaySorted(test); }
TEST(gogame_move_check, single_piece_surrounded) { uint8_t board_size = 3; GoBoard test_board(board_size); test_board.board[0][1] = get_mask(1); test_board.board[2][1] = get_mask(1); test_board.board[1][0] = get_mask(1); test_board.board[1][2] = get_mask(1); GoMove test_move(test_board, XYCoordinate(1, 1)); EXPECT_EQ(0, test_move.check_move(0)); }
void zeromq_thread() { { void* objectContext = zmq_ctx_new(); void* objectSocket = zmq_socket(objectContext, ZMQ_PAIR); { char charZeromq[1024] = { }; sprintf(charZeromq, "tcp://localhost:%d", main_intZeromq); if (zmq_connect(objectSocket, charZeromq) == -1) { printf("zeromq: %s\n", zmq_strerror(zmq_errno())); } } { zeromq_objectSocket = objectSocket; } { void* objectMonitor = zmq_socket(objectContext, ZMQ_PAIR); { if (zmq_socket_monitor(objectSocket, "inproc://minichess-zeromq-monitor", ZMQ_EVENT_ALL) == -1) { printf("zeromq: %s\n", zmq_strerror(zmq_errno())); } if (zmq_connect(objectMonitor, "inproc://minichess-zeromq-monitor") == -1) { printf("zeromq: %s\n", zmq_strerror(zmq_errno())); } } { do { int intEventspecifier = 0; int intEventvalue = 0; char charEventaddress[256] = { }; #if (ZMQ_VERSION_MAJOR == 3) { zmq_msg_t objectMessage = { }; zmq_msg_init(&objectMessage); if (zmq_recvmsg(objectMonitor, &objectMessage, 0) == -1) { printf("zeromq: %s\n", zmq_strerror(zmq_errno())); } zmq_event_t objectEvent = { }; memcpy(&objectEvent, zmq_msg_data(&objectMessage), sizeof(objectEvent)); intEventspecifier = objectEvent.event; intEventvalue = 0 charEventaddress[0] = '\0'; zmq_msg_close(&objectMessage); } #elif (ZMQ_VERSION_MAJOR == 4) { zmq_msg_t objectMessage = { }; zmq_msg_init(&objectMessage); if (zmq_recvmsg(objectMonitor, &objectMessage, 0) == -1) { printf("zeromq: %s\n", zmq_strerror(zmq_errno())); } uint8_t* intData = (uint8_t*) (zmq_msg_data(&objectMessage)); intEventspecifier = *(uint16_t*) (intData + 0); intEventvalue = *(uint32_t*) (intData + 2); zmq_msg_close(&objectMessage); } { zmq_msg_t objectMessage = { }; zmq_msg_init(&objectMessage); if (zmq_recvmsg(objectMonitor, &objectMessage, 0) == -1) { printf("zeromq: %s\n", zmq_strerror(zmq_errno())); } charEventaddress[0] = '\0'; zmq_msg_close(&objectMessage); } #endif { if (intEventspecifier == ZMQ_EVENT_CONNECTED) { { zeromq_boolConnected = true; webserver_broadcast("zeromq_status", NULL); } { cJSON* objectOut = cJSON_CreateObject(); cJSON* objectIn = NULL; { cJSON_AddStringToObject(objectOut, "strFunction", "ping"); } { zeromq_send(objectOut); objectIn = zeromq_recv(); } { strcpy(zeromq_charClient, cJSON_GetObjectItem(objectIn, "strOut")->valuestring); webserver_broadcast("zeromq_name", NULL); } cJSON_Delete(objectOut); cJSON_Delete(objectIn); } { printf("zeromq: connected to %s\n", zeromq_charClient); } } else if (intEventspecifier == ZMQ_EVENT_DISCONNECTED) { { zeromq_boolConnected = false; webserver_broadcast("zeromq_status", NULL); } { printf("zeromq: disconnected from %s\n", zeromq_charClient); } } } { if (intEventspecifier == ZMQ_EVENT_CONNECTED) { int intTest = 0; if (intTest > 0) { setbuf(stdout, NULL); } if (intTest > 0) { printf("test_board: "); printf("%d\n", test_board()); } if (intTest > 1) { printf("test_winner: "); printf("%d\n", test_winner()); } if (intTest > 2) { printf("test_isValid: "); printf("%d\n", test_isValid()); } if (intTest > 3) { printf("test_isEnemy: "); printf("%d\n", test_isEnemy()); } if (intTest > 4) { printf("test_isOwn: "); printf("%d\n", test_isOwn()); } if (intTest > 5) { printf("test_isNothing: "); printf("%d\n", test_isNothing()); } if (intTest > 6) { printf("test_eval: "); printf("%d\n", test_eval()); } if (intTest > 7) { printf("test_moves: "); printf("%d\n", test_moves()); } if (intTest > 8) { printf("test_move: "); printf("%d\n", test_move()); } if (intTest > 9) { printf("test_undo: "); printf("%d\n", test_undo()); } if (intTest > 10) { printf("test_movesShuffled: "); printf("%d\n", test_movesShuffled()); } if (intTest > 11) { printf("test_movesEvaluated: "); printf("%d\n", test_movesEvaluated()); } if (intTest > 12) { printf("test_moveRandom: "); printf("%d\n", test_moveRandom()); } if (intTest > 13) { printf("test_moveGreedy: "); printf("%d\n", test_moveGreedy()); } if (intTest > 14) { printf("test_moveNegamax: "); printf("%d\n", test_moveNegamax()); } if (intTest > 15) { printf("test_moveAlphabeta: "); printf("%d\n", test_moveAlphabeta()); } } } } while (pthread_mutex_trylock(&zeromq_objectRunning) != 0); pthread_mutex_unlock(&zeromq_objectRunning); } zmq_close(objectMonitor); } zmq_close(objectSocket); zmq_ctx_destroy(objectContext); } }