/** * This function read a position by clicking in * the HTML interface's board * * @v info_s when the HTML interface is chosen * @return void * @date 2014-05-13 * @author PL Team **/ void PL_HTMLread_move(position_t *pos) { /* Maximum size for the buffer to read a move: 3 characters + 1 \n + 1 \0 => 5 */ #define READ_MOVE_MAX_BUFF_LEN (5) //The move_in_board (being the move read from the user) is 5 to verify the length of the input //char move_in_board[READ_MOVE_MAX_BUFF_LEN]; char move_in_board[READ_MOVE_MAX_BUFF_LEN]; // Maximum number of characters we want to read with fgets (includes '\n' and '\0') int maxLength = READ_MOVE_MAX_BUFF_LEN; //This allows one more character in order to verify the length of the input FILE *mov; startServer(); printf("Write your move [3 characters max]: "); //fgets(move_in_board, maxLength, stdin); //gets in the string move_in_board a maximum of maxLength characters coming from the STDIN mov = fopen("move.mv","r+"); fgets(move_in_board, maxLength, mov); fclose(mov); /* Terminate the string at the first \n */ terminate_string_at_first_slash_n(move_in_board); pos->X = input_is_digit(move_in_board); pos->Y = input_is_char(move_in_board); pos->Y = toupper(pos->Y); pos->Y_int = board_col_to_matrix_idx(pos->Y); }
void read_move1(position_t *pos) { /* Maximum size for the buffer to read a move: 3 characters + 1 \n + 1 \0 => 5 */ #define READ_MOVE_MAX_BUFF_LEN (5) int dimension = board_get_size(); //The move_in_board (being the move read from the user) is 5 to verify the length of the input // char move_in_board[READ_MOVE_MAX_BUFF_LEN]; char move_in_board[READ_MOVE_MAX_BUFF_LEN]; // Maximum number of characters we want to read with fgets (includes '\n' and '\0') int maxLength = READ_MOVE_MAX_BUFF_LEN; //This allows one more character in order to verify the length of the input // Keep the number of char in the move_in_board string size_t move_in_board_strlen; do { do { printf("Write your move [3 characters max]: "); fgets(move_in_board, maxLength, stdin); //gets in the string move_in_board a maximum of maxLength characters coming from the STDIN /* Terminate the string at the first \n */ terminate_string_at_first_slash_n(move_in_board); /* Compute # of chars in move_in_board */ move_in_board_strlen = strlen(move_in_board); if( move_in_board_strlen > 3) { clean_buffer_keyboard(); printf("The move has a maximum of three characters!\n"); } } while(move_in_board_strlen > 3); pos->X = input_is_digit(move_in_board); pos->Y = input_is_char(move_in_board); pos->Y = toupper(pos->Y); pos->Y_int = board_col_to_matrix_idx(pos->Y); //extern int board_col_to_matrix_idx(char col); if(pos->X < 1 || pos->X > dimension) { printf("Invalid number!\nThe number has to be between 1 - %d\n\n", dimension); } if(pos->Y_int == -1 || pos->Y_int >= dimension) { printf("Invalid letter!\nIt has to be between A - %c\n\n", 64+dimension); } } while(pos->Y_int == -1 || pos->Y_int >= dimension || pos->X < 1 || pos->X > dimension); printf("Part of the board! \n"); }
/** * Sets the content of the board in a specific row and column * The content is a define, which is the piece * * @v board_size PIECE is the define of '#' * @return void * @date 2014-04-14 * @author Triplet VIOPE 2014 (PT TEAM) */ void board_set_content_row_col(int row, char col){ position_t pos; pos.X = board_row_to_matrix_idx(row); pos.Y_int = board_col_to_matrix_idx(col); get_current_game_ptr()->board[pos.X][pos.Y_int] = PIECE; }
/** * Gets the content of the board in a specific row and column * The content is a char * * @v board_size "piece_on" is the char in that position * @return The char in that position * @date 2014-04-14 * @author Triplet VIOPE 2014 (PT TEAM) */ char board_get_content_row_col(int row, char col){ char piece_on; //matrix -> get_current_game->board[i][j]; position_t pos; pos.X = board_row_to_matrix_idx(row); pos.Y_int = board_col_to_matrix_idx(col); piece_on = get_current_game_ptr()->board[pos.X][pos.Y_int]; //get_current_game_ptr()->board[i][j] return piece_on; }