Пример #1
0
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");

}
/**
 * This function reads a number from the user
 * that represents the row in the board
 *
 * @v info_s	Just to play the column mode
 * @return  void
 * @date	2014-05-20
 * @author	Gabriel Rodrigues (PT Team)
 **/
void read_row(position_t *pos){

    int control;
    int dimension = board_get_size();
    do
    {
        printf("Write your move: %c", pos->Y);
        control = scanf("%d", &pos->X);

        if(pos->X < 1 || pos->X > dimension || control == 0)
        {
            printf("Invalid number!\nThe number has to be between 1 - %d\n", dimension);
        }
        clean_buffer_keyboard();
    }
    while(pos->X < 1 || pos->X > dimension || control == 0);

//    if the move reach this point is because is -> printf("Part of the board! \n");

}
Пример #3
0
/**
 * Print the current board
 * @return None
 * @date 2014-04-21
 * @author  PL team -Triplet VIOPE 2014
 */
void board_print_raw(void){
	int i,j,k,l,m;
	int board_size = board_get_size();
	printf("[INFO] Board: %d x %d\n", board_size,board_size);
	if(board_size==BOARD_SMALL){
		printf("     GAME BOARD\n");}
	if(board_size==BOARD_MEDIUM){
		printf("           GAME BOARD\n");}
	if(board_size==BOARD_LARGE){
		printf("                     GAME BOARD\n");}

	for(i=0;i<board_size;i++){
		printf("    ");
		for(k=0;k<board_size;k++){
			printf("+---");}
		printf("+\n");
		if (i>8){
			printf(" %d ",i+1);
		}
		else{
			printf("  %d ",i+1);
		}
		for(j=0;j<board_size;j++){
			printf("| ");
			printf("%c ", get_current_game_ptr()->board[i][j]);
		}
		printf("|\n");
	}
	printf("    ");
	for(l=0;l<board_size;l++){
		printf("+---");}
	printf("+\n     ");
	char f=65;
	for(m=0;m<board_size;m++){
		printf(" %c  ",f);
		f=f+1;}
	printf("\n");
}
void test_reading_converting_validating()
{
    int counter = 1, check = 0;
    reset_data_structs();
    board_set_size(BOARD_MEDIUM);
    int dimension = board_get_size();
    position_t pos;

    while(counter == 1)
    {
        test_representation_matrix(get_current_game_ptr()->board, dimension);

        do
        {
            read_move(&pos);

            check = function_validate_move(pos);
        }
        while(check != 0);
        //arise the variable "int playNumber".
        //save in log
    }
}