/** * Function to set the board size * * @v board_size value to use for board size * @return 0 if the specified board size is invalid, otherwise it returns * the board size * @date 2014-03-31 * @author Triplet VIOPE 2014 */ int board_set_size(const int board_size) { if( ! board_is_valid_size(board_size) ){ fprintf(stderr, "[Err] Invalid board size:%d\n", board_size); return 0; } /* Setting the board size */ get_current_game_ptr()->board_rows = board_size; /* Clear board */ board_set_empty(); return board_size; }
/** * Function that resets the data structs with invalid values * so that we can detect when we're using unitialized data members * * @return void * @date 2014-03-31 * @author Triplet VIOPE 2014 */ void reset_data_structs(void){ game_t *game_ptr; int i; game_ptr = get_current_game_ptr(); game_ptr->player_first = -1; game_ptr->board_columns = -1; game_ptr->board_rows = -1; game_ptr->game_mode = -1; /* Set the whole board as empty */ board_set_empty(); /* Deal with G_players */ for(i=0;i<2;i++){ player_reset(&(get_players_ptr()[i])); } }
void loadLogs(int gameCounter) { FILE *playLog; int playNumber; char dateExtended[32]; char playerName[30]; int dimension; int i; int moveX; char moveY; int lineCounter=0; int headLinesNumber=6; char logName[255]; sprintf(logName, "data/logs/TripletsLog-%d.txt", gameCounter); lineCounter=get_file_lines(logName); lineCounter-=headLinesNumber; lineCounter++; // to add the last line which doesn't have /n !! playLog = fopen(logName, "rt"); if(playLog == NULL) { printf("\n\tERR: Unable to read Log!"); } else { gameCounter=0; dimension=0; fscanf(playLog, "--Triplets Log--\n"); fscanf(playLog, "Game #%d\n", &gameCounter); fscanf(playLog, "Matrix Dimension: %dx%d\n", &dimension, &dimension); fscanf(playLog, "Started on: %s\n", dateExtended); board_set_size(dimension); board_set_empty(); clearscr(); board_print_raw(); init_players(); for (i=0; i<lineCounter; i++) { printf("\nPress any key to print next move..."); readchar(); clearscr(); fscanf(playLog, "Player %s ; Play %d ; Move [%d][%c]\n", playerName, &playNumber, &moveX, &moveY); board_set_content_row_col(moveX, moveY); if (i==lineCounter-1) { finish_gamePL(get_current_game_ptr()->board); } board_print_raw(); printf("\nPlayer Name: %s - Play Number: %d - Move: [%d][%c]\n",playerName, playNumber, moveX, moveY); // was just to test if it's reading right cmp.tmp=cmp.current_player_move; //swap current player cmp.current_player_move=cmp.previous_player_move; // cmp.previous_player_move=cmp.tmp; } printf("\nWINNER: %s\a\n", playerName); printf("\nPress any key to go back to menu..."); readchar(); } fclose(playLog); }