-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
51 lines (38 loc) · 1.16 KB
/
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
43
44
45
46
47
48
49
50
51
/**
* @file main.c
* @author Gyeongtae Kim(dev-dasae) <[email protected]>
*
* @brief Main entry point for the Omok game.
* @details This file contains the main function that initializes the Omok game and starts the game loop.
*
* @version 0.1
* @date 2024-06-21
*
* @copyright Released under the MIT License. See LICENSE file for details.
*/
#include "omok.h"
#include <stdio.h>
int main() {
Board board = { 0 };
Board_init(&board);
char current_player = 'X';
while (true) {
Board_print(&board);
printf("Player %c's turn.\n", current_player);
printf("Enter the row and column (0-14) separated by a space: ");
Point move = { 0 };
(void)scanf("%d %d", &move.x, &move.y);
if (!Board_isValidMove(&board, move)) {
printf("Invalid move. Try again.\n");
continue;
}
board.grid[move.x][move.y] = current_player;
if (Board_hasWinner(&board, move)) {
Board_print(&board);
printf("Player %c wins!\n", current_player);
break;
}
current_player = (current_player == 'X') ? 'O' : 'X';
}
return 0;
}