-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
42 lines (34 loc) · 856 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "main.h"
#include <stdio.h>
int main() {
char board[3][3];
char currentPlayer = 'X'; // Player starts first
char computerPlayer = 'O';
int gameStatus = 0;
initializeBoard(board);
printf("Welcome to Tic-Tac-Toe!\n");
while (gameStatus == 0) {
printBoard(board);
if (currentPlayer == 'X') {
playerMove(board, currentPlayer);
} else {
computerMove(board, computerPlayer);
}
if (checkWin(board)) {
gameStatus = 1;
} else if (checkTie(board)) {
gameStatus = 2;
} else {
currentPlayer = (currentPlayer == 'X') ? 'O' : 'X';
}
}
printBoard(board);
if (gameStatus == 1) {
printf("Player %c wins!\n",
(currentPlayer == 'X') ? currentPlayer : computerPlayer);
} else {
printf("It's a tie!\n");
}
printf("Thanks for playing!\n");
return 0;
}