목차
코딩시 아래 5개 함수를 사용하였습니다.
void initialize(char board[SIZE][SIZE]); 보드 초기화 함수
void print_board(char board[SIZE][SIZE]); 보드 출력 함수
int is_winner(char board[SIZE][SIZE]); 승자 확인 함수
int is_full(char board[SIZE][SIZE]); 보드 full 여부 확인 함수
int check_move(char board[SIZE][SIZE], int x, int y); 이동이 타당여부 확인 함수
void initialize(char board[SIZE][SIZE]); 보드 초기화 함수
void print_board(char board[SIZE][SIZE]); 보드 출력 함수
int is_winner(char board[SIZE][SIZE]); 승자 확인 함수
int is_full(char board[SIZE][SIZE]); 보드 full 여부 확인 함수
int check_move(char board[SIZE][SIZE], int x, int y); 이동이 타당여부 확인 함수
본문내용
//Function Prototypes
void initialize(char board[SIZE][SIZE]);
void print_board(char board[SIZE][SIZE]);
int is_winner(char board[SIZE][SIZE]);
int is_full(char board[SIZE][SIZE]);
int check_move(char board[SIZE][SIZE], int x, int y);
//Main Function
int main() {
//Declare necessary variables
char board[3][3];
int turn = 2, x, y;
char play;
//Initialize the game board
initialize(board);
//Information for the users
printf(\"Player 1 will be X.nPlayer 2 will be O.n\");
//Alternate turns for the users until the board is full
while (!is_full(board)) {
//Set user\'s turn
if (turn == 2) {
turn = 1;
play = \'X\';
}
else {
turn = 2;
play = \'O\';
}
//Announce whose turn it is
printf(\"It is player %d\'s turn.n\", turn);
//Print board
print_board(board);
//Ask user for their move
printf(\"nWhere would you like to go?t X Yn\");
scanf(\"%d %d\", &x, &y);
//Verify the move is valid
while (!check_move(board, x-1, y-1)) {
printf(\"Sorry, that move was not valid.n\");
printf(\"Where would you like to go?t X Yn\");
scanf(\"%d %d\", &x, &y);
}
//Put user\'s move on the board
board[y-1][x-1] = play;
//Check to see if there is a winner
if (is_winner(board)) {
break;
}
}
//Print the board a final time
print_board(board);
return 0;
}
void initialize(char board[SIZE][SIZE]);
void print_board(char board[SIZE][SIZE]);
int is_winner(char board[SIZE][SIZE]);
int is_full(char board[SIZE][SIZE]);
int check_move(char board[SIZE][SIZE], int x, int y);
//Main Function
int main() {
//Declare necessary variables
char board[3][3];
int turn = 2, x, y;
char play;
//Initialize the game board
initialize(board);
//Information for the users
printf(\"Player 1 will be X.nPlayer 2 will be O.n\");
//Alternate turns for the users until the board is full
while (!is_full(board)) {
//Set user\'s turn
if (turn == 2) {
turn = 1;
play = \'X\';
}
else {
turn = 2;
play = \'O\';
}
//Announce whose turn it is
printf(\"It is player %d\'s turn.n\", turn);
//Print board
print_board(board);
//Ask user for their move
printf(\"nWhere would you like to go?t X Yn\");
scanf(\"%d %d\", &x, &y);
//Verify the move is valid
while (!check_move(board, x-1, y-1)) {
printf(\"Sorry, that move was not valid.n\");
printf(\"Where would you like to go?t X Yn\");
scanf(\"%d %d\", &x, &y);
}
//Put user\'s move on the board
board[y-1][x-1] = play;
//Check to see if there is a winner
if (is_winner(board)) {
break;
}
}
//Print the board a final time
print_board(board);
return 0;
}
소개글