-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.c
52 lines (39 loc) · 942 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
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "Board.h"
#include "Search.h"
int
main(int argc, char **argv)
{
printf("Welcome to TicTacToe.\n");
printf("Would you like to move first? [y/n]: ");
char resp;
scanf("%c", &resp);
bool player_is_x = (resp == 'y');
Board* board = b_init();
while (true)
{
if (b_result(board) != NIL)
break;
if (board->x_to_move == player_is_x)
{
b_print(board);
printf("Please enter your move: ");
int move;
scanf("%d", &move);
b_move(board, move);
}
else
{
Node* comp = s_negamax(board);
b_move(board, comp->best_move);
}
}
b_print(board);
char* res_str = b_result_str(b_result(board));
printf("\n%s\n\n", res_str);
free(board);
free(res_str);
return 0;
}