/** * second play is tested over first play * the second play adds 3 words to the board by amending tiles to the existing word to form 3 new words *\author Abdallah */ void test_second_valid3() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('h'); t2 = new_tile('a'); t3 = new_tile('s'); t4 = new_tile ('r'); t5 = new_tile('e'); t6 = new_tile('m'); t7 = new_tile('d'); board_prev[7][7] = &t1; board_prev[8][7] = &t2; board_prev[9][7] = &t3; board[7][7] = &t1; board[8][7] = &t2; board[9][7] = &t3; board[6][8] = &t4; board[7][8] = &t5; board[8][8] = &t6; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected value : 21\nR(1)*2 + E(1) + M(3)*2 = 9\nH(4) + E (1) =5 \nA(1) + M(3)*2 = 7\n"); }
/** The added word is invalid in term of position (horizontally) but it does not exist in the dictionary *\author Abdallah */ void test_horizontal_invalid () { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); bag real_bag, inhand_bag; tile t1,t2, t3, t4;// tiles to be used for testing purposesone for the real bag and the other for hand real_bag = new_real_bag();//initializing the real bag inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag //Testing horizontal "to" t1 = new_tile('t'); t2 = new_tile('w'); t3 = new_tile('o'); t4 = new_tile ('x'); board[7][7] = &t1; board[7][8] = &t2; board[7][9] = &t3; board[7][6] = &t4; display_board(board); display_bag (inhand_bag); char new_word [word_len]; check_board ( board , board_prev , str , & temp_score); }
/** The added word is valid in term of position (vertically) and exists in the dictionary *\author Abdallah */ void test_vertical_valid () { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); bag real_bag, inhand_bag; tile t1,t2, t3, t4;// tiles to be used for testing purposesone for the real bag and the other for hand real_bag = new_real_bag();//initializing the real bag inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag //Testing horizontal "to" t1 = new_tile('l'); t2 = new_tile('o'); t3 = new_tile('s'); t4 = new_tile ('e'); board[7][7] = &t1; board[8][7] = &t2; board[9][7] = &t3; board[10][7] = &t4; display_board(board); display_bag (inhand_bag); char new_word [word_len]; check_board ( board , board_prev , str , & temp_score); printf("The word added to the board is %s\n",str [0] ); }
/** * second play is tested over first play * the second play adds a word that exists in the dictionary but is nor properly connected *\author Abdallah */ void test_second_invalid2() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('h'); t2 = new_tile('a'); t3 = new_tile('s'); t4 = new_tile ('r'); t5 = new_tile('e'); t6 = new_tile('m'); t7 = new_tile('d'); board_prev[7][7] = &t1; board_prev[8][7] = &t2; board_prev[9][7] = &t3; board[7][7] = &t1; board[8][7] = &t2; board[9][7] = &t3; board[6][1] = &t4; board[7][1] = &t5; board[8][1] = &t6; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); }
/** * A word placed but not passing by the central square * \author Abdallah */ void test_invalid4() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); bag real_bag, inhand_bag; tile t1,t2, t3, t4;// tiles to be used for testing purposesone for the real bag and the other for hand real_bag = new_real_bag();//initializing the real bag inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag t1 = new_tile('g'); t2 = new_tile('o'); t3 = new_tile('o'); t4 = new_tile ('d'); board[7][8] = &t1; board[7][9] = &t2; board[7][10] = &t3; board[7][11] = &t4; display_board(board); display_bag (inhand_bag); char new_word [word_len]; check_board ( board , board_prev , str , & temp_score); printf("Invalid placement \n"); }
/** * nth play where the board is in a valid state that can occur after one or more plays the added tiles are valid and pass by a triple word square * \author Abdallah */ void test_nth_valid3() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('c'); t2 = new_tile('l'); t3 = new_tile('a'); t8 = new_tile('n'); t4 = new_tile ('o'); t5 = new_tile('v'); t6 = new_tile('a'); t7 = new_tile('l'); t9 = new_tile('o'); t10 = new_tile ('n'); board_prev[7][7] = &t1; board_prev[7][8] = &t2; board_prev[7][9] = &t3; board_prev[7][10] = &t8; board_prev[6][10] = &t4; board_prev[6][11] = &t5; board_prev[6][12] = &t6; board_prev[6][13] = &t7; board [7][7] = &t1; board [7][8] = &t2; board [7][9] = &t3; board [7][10] = &t8; board [6][10] = &t4; board [6][11] = &t5; board [6][12] = &t6; board [6][13] = &t7; board[7][13] = &t9; board[7][14] = &t10; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected added score is 8\nL(1) + O (1) =2 \n( O(1) + N (1) )*3 = 6\n"); }
/** The added word is valid in term of position (horizontally) exists in the dictionary *\author Abdallah */ void test_horizontal_valid () { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); bag real_bag, inhand_bag; tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; real_bag = new_real_bag();//initializing the real bag inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag //tested word:holocrystalline, longest possible (15 letters) t1 = new_tile('h'); t2 = new_tile('o'); t3 = new_tile('l'); t4 = new_tile ('o'); t5 = new_tile('c'); t6 = new_tile('r'); t7 = new_tile('y'); t8 = new_tile ('s'); t9 = new_tile('t'); t10 = new_tile('a'); t11= new_tile('l'); t12= new_tile ('l'); t13= new_tile ('i'); t14= new_tile ('n'); t15= new_tile ('e'); board[7][0] = &t1; board[7][1] = &t2; board[7][2] = &t3; board[7][3] = &t4; board[7][4] = &t5; board[7][5] = &t6; board[7][6] = &t7; board[7][7] = &t8; board[7][8] = &t9; board[7][9] = &t10; board[7][10] = &t11; board[7][11] = &t12; board[7][12] = &t13; board[7][13] = &t14; board[7][14] = &t15; display_board(board); display_bag (inhand_bag); char new_word [word_len]; check_board ( board , board_prev , str , & temp_score ); printf("The word added to the board is %s\n",str [0] ); }
void test_new_board() { Board* board = new_board(3); for(int i = 0; i < 9; i++) { assert(get_space(board, i) == '-'); } destroy_board(board); }
void test_invalid_move() { Board* board = new_board(3); make_move(board, 0, 'X'); bool check = is_valid_move(board, 0); assert(!check); destroy_board(board); }
void test_get_move() { freopen("test/fixtures/test_input.txt", "r", stdin); Board* board = new_board(3); int move = ask_for_move(board, 'X', 'O'); destroy_board(board); assert(move == 5); }
void test_display_empty_board() { Board* board = new_board(3); char expected[] = "1 2 3 4 5 6 7 8 9 "; show_board(board); destroy_board(board); assert(strstr(writer_log, expected)); }
void test_add_thread() { Board *board; Thread *thread; board = new_board("test", "TEST", 2, 0); assert(board != NULL); thread = new_thread(NULL, 0, 0); /* Add the first thread */ add_thread_to_board(board, thread); assert(board->first_thread == 0); assert(board->last_thread == 0); /* Add a second thread */ add_thread_to_board(board, thread); assert(board->first_thread == 0); assert(board->last_thread == 1); /* Make sure the post count hasn't magically changed */ assert(board->post_count == 0); /* Add a third thread, should remove the first one */ add_thread_to_board(board, thread); assert(board->first_thread == 1); assert(board->last_thread == 0); /* Check post count again */ assert(board->post_count == 0); free_board(board); free_thread(thread); }
int UCTSearch(int MSQ[M_Sequence_Limit], int hn,int *wins,int *visits) { if (hn > Open_Step_Limit) { if (MSQ[hn-1] == PASS && MSQ[hn-3] == PASS) { return PASS; } } Board new_board(MSQ, hn, UCT_Komi); // 取得當前盤面資訊 if (new_board.get_LegalNum() == 0) //若沒有著手可下,則虛手 { return PASS; } root = new Node(-new_board.get_color(), 0, MSQ[hn]); // color, level, move create_Tree(root, &new_board, hn); build_Tree(root, &new_board); int result = root->get_NodesValues(wins,visits);//最佳落子點 root沒小孩為0,有為1 root->delete_Tree(); return result; }
/** The player tries to play the first turn without adding any tiles, a warning message is displayed to ask him to add a tile passing through the center *\author Abdallah */ void test_empty() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); bag real_bag, inhand_bag; real_bag = new_real_bag();//initializing the real bag inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag display_board(board); display_bag (inhand_bag); char new_word [word_len]; check_board ( board , board_prev , str , & temp_score); printf("Invalid placement; no tiles \n"); }
void gameOfLife(vector<vector<int>>& board) { int m = board.size(); if (m == 0) return; int n = board[0].size(); vector<vector<int> > new_board(board); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { // count alive neighbors int count = 0; for (int ii = max(0, i-1); ii < min(m, i+1+1); ii++) { for (int jj = max(0, j-1); jj < min(n, j+1+1); jj++) { if (board[ii][jj] == 1) count++; } } if (board[i][j] == 1) { // alive count--; if (count < 2) new_board[i][j] = 0; else if (count > 3) new_board[i][j] = 0; } else { // dead if (count == 3) new_board[i][j] = 1; // realive } } } board = new_board; return; }
void test_board_is_full() { Board* board = new_board(3); for(int i = 0; i < 9; i++) { make_move(board, i, 'X'); } assert(is_full(board)); destroy_board(board); }
void test_board_is_done() { Board* board = new_board(3); make_move(board, 6, 'X'); make_move(board, 7, 'X'); make_move(board, 8, 'X'); assert(is_done(board)); destroy_board(board); }
/** * nth play where the board is in a valid state that can occur after one or more plays the added tiles are valid and pass by a double word square * \author Abdallah */ void test_nth_valid2() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('c'); t2 = new_tile('l'); t3 = new_tile('a'); t8 = new_tile('n'); t4 = new_tile ('n'); t5 = new_tile('o'); t6 = new_tile('n'); t7 = new_tile('e'); board_prev[7][7] = &t1; board_prev[7][8] = &t2; board_prev[7][9] = &t3; board_prev[7][10] = &t8; board_prev[8][10] = &t5; board_prev[9][10] = &t6; board [7][7] = &t1; board [7][8] = &t2; board [7][9] = &t3; board [7][10] = &t8; board[8][10] = &t5; board[9][10] = &t6; board[10][10] = &t7; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected added score is 8\n"); }
void test_second_valid () { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('f'); t2 = new_tile('i'); t3 = new_tile('l'); t4 = new_tile ('l'); t5 = new_tile('e'); t6 = new_tile('d'); t7 = new_tile('y'); t8 = new_tile ('s'); t9 = new_tile('t'); t10 = new_tile('a'); t11= new_tile('l'); t12= new_tile ('l'); t13= new_tile ('i'); t14= new_tile ('n'); t15= new_tile ('e'); board_prev[7][7] = &t1; board_prev[7][8] = &t2; board_prev[7][9] = &t3; board_prev[7][10] = &t4; board[7][7] = &t1; board[7][8] = &t2; board[7][9] = &t3; board[7][10] = &t4; board[7][11] = &t5; board[7][12] = &t6; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected added value : 11\nF(4) + I(1) + L (1) + L (1) +E (1)*2 + D (2) \n"); temp_score = 0; }
void test_board_is_won_row() { Board* board = new_board(3); assert(!is_won(board)); make_move(board, 0, 'X'); make_move(board, 1, 'X'); make_move(board, 2, 'X'); assert(is_won(board)); destroy_board(board); }
void test_board_is_won_column() { Board* board = new_board(3); assert(!is_won(board)); make_move(board, 0, 'X'); make_move(board, 3, 'X'); make_move(board, 6, 'X'); assert(is_won(board)); destroy_board(board); }
void test_board_is_won_diag2() { Board* board = new_board(3); assert(!is_won(board)); make_move(board, 2, 'X'); make_move(board, 4, 'X'); make_move(board, 6, 'X'); assert(is_won(board)); destroy_board(board); }
/* * This is the main loop of the connect four game. It first prints a * welcome message, allocates the board, and then begins the game loop */ int main() { puts("Welcome to Connect Four\n"); int* board = new_board(); while (1) { print_board(board); int column = -1; // Get human input until they enter a valid choice... while (1) { printf("Enter your move (column number): "); scanf("%d", &column); if (column < 0 || column >= WIDTH) { printf("Input a valid choice (0 - 6).\n"); } else if (place(board, column, 1) == 0) { printf("That column is full.\n"); } else { break; } } // Did the human input make him or her win? if (check_win(board, 1) != 0) { print_board(board); printf("Player 1 wins!\n"); break; } // Do the AI's move... int ai_column = get_next_move(evaluate_board(board)); place(board,ai_column, 2); // Did the AI's move cause it to win? if (check_win(board, 2) != 0) { print_board(board); printf("Player 2 wins!\n"); break; } } free(board); exit(EXIT_SUCCESS); }
void test_board_finds_winner() { Board* board = new_board(3); make_move(board, 2, 'X'); make_move(board, 1, 'O'); make_move(board, 4, 'X'); make_move(board, 0, 'O'); make_move(board, 6, 'X'); assert(winner(board) == 'X'); destroy_board(board); }
std::vector<unsigned> Map::rotate(const std::vector<unsigned>& board) const { std::vector<unsigned> new_board(board.size(), 0); //new_board.reserve(board.size()); for (unsigned i = 0; i < BOARD_DIM; i++) { for (unsigned j = 0; j < BOARD_DIM; j++) { new_board[j*BOARD_DIM + (BOARD_DIM - 1 - i)] = board[i*BOARD_DIM + j]; } } return new_board; }
void build_Tree(Node *r, Board *b) { int nsim = 0; while (nsim < MaxSimulation) { Board new_board(b); play_Simulation(&new_board, r); nsim++; } }
/** * second play is tested over first play * the second play adds 4 words to the board by amending tiles to the existing word to form 4 new words * this give me a huge error but from the analysis I can assume it is from the part when the the char is changed to int and vice versa because if the tenth is changed from 1 to 0 the answer would be correct *\author Abdallah */ void test_second_valid4() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('h'); t2 = new_tile('a'); t3 = new_tile('i'); t8 = new_tile('r'); t4 = new_tile ('r'); t5 = new_tile('e'); t6 = new_tile('m'); t7 = new_tile('s'); board_prev[7][7] = &t1; board_prev[7][8] = &t2; board_prev[7][9] = &t3; board_prev[7][10] = &t8; board [7][7] = &t1; board [7][8] = &t2; board [7][9] = &t3; board [7][10] = &t8; board[8][6] = &t4; board[8][7] = &t5; board[8][8] = &t6; board[8][9] = &t7; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected value is 10 + 5 + 7 + 2 = 24 \n"); }
int main() // int argc, char* argv) { init_stats(&stats); board_t* board = new_board(); if (false == load_board(board)) { printf("bad board\n"); } else { printf("loaded board:\n"); print_board(board); solve_board(board); } // print_board(board); return 0; }
/** * @brief Creates a new tetris game. * * @param width board width (10 in standard Tetris; must be lower than or equal to 14) * @param height board height (20 in standard Tetris) * @param allow_lines_after_overflow 1 to enable the lines completion when the piece overflows * @param pieces_file_name a file describing the pieces (pieces4.dat for standard Tetris) * @param piece_sequence a predeterminated sequence of pieces, or NULL to generate the pieces randomly; * the sequence of pieces must be a NULL-terminated array of pieces indexes * @return the game created * @see new_standard_game(), new_game_from_parameters(), new_game_copy(), free_game() */ Game *new_game(int tetris_implementation, int width, int height, int allow_lines_after_overflow, const char *pieces_file_name, int *piece_sequence) { Game *game; MALLOC(game, Game); MALLOC(game->piece_configuration, PieceConfiguration); load_pieces(pieces_file_name, &game->piece_configuration->nb_pieces, &game->piece_configuration->pieces); game->tetris_implementation = tetris_implementation; game->board = new_board(width, height, allow_lines_after_overflow, game->piece_configuration->nb_pieces, game->piece_configuration->pieces); game->piece_configuration->piece_sequence = piece_sequence; game->piece_configuration->nb_games = 1; game_reset(game); return game; }
void test_create_board() { Board *board; board = new_board("test", "Test", 1, 0); assert(board != NULL); assert(strcmp(board->name, "test") == 0); assert(strcmp(board->fullname, "Test") == 0); assert(board->max_threads == 1); assert(board->threads != NULL); assert(board->first_thread == -1); assert(board->last_thread == -1); assert(board->post_count == 0); free_board(board); }