-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
115 lines (91 loc) · 1.85 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//main file
#include <stdlib.h>
#include <stdio.h>
#include <ncurses.h>
#include <time.h>
//functions in logic.c
void clean_table(int *table);
int test_win(int *table, int turn);
void inputfunc(int *table, int turn, int *xs, int *os, int *cpoint);
//functions in visual.c
void print_table(int *table, int hlight);
void win_message(int turn);
int menu();
//functions in ai.c
void ai_move(int *table, int *os);
int two_player_loop(){
int *table = (int *) malloc(9 * sizeof(int));
int *xs = (int *) malloc(sizeof(int));
int *os = (int *) malloc(sizeof(int));
int *cpoint = (int *) malloc(2 * sizeof(int));
int win;
int turn;
clean_table(table);
turn = 1;
win = 0;
*xs = 0;
*os = 0;
cpoint[0] = 1;
cpoint[1] = 1;
while(win == 0){
clear();
inputfunc(table, turn, xs, os, cpoint);
win = test_win(table, turn);
if (win == 1){
print_table(table, 0);
win_message(turn);
}
if (turn == 1){turn = 2;}
else if (turn == 2){turn = 1;}
}
free(table);
free(xs);
free(os);
free(cpoint);
}
int one_player_loop(){
time_t t;
srand((unsigned) t);
clear();
refresh();
int startx, starty, height, width, lines, cols;
int *table = (int *) malloc(9 * sizeof(int));
int *xs = (int *) malloc(sizeof(int));
int *os = (int *) malloc(sizeof(int));
int *cpoint = (int *) malloc(2 * sizeof(int));
int win;
int turn;
clean_table(table);
turn = 1;
win = 0;
*xs = 0;
*os = 0;
cpoint[0] = 1;
cpoint[1] = 1;
while(win == 0){
clear();
if (turn == 1){inputfunc(table, turn, xs, os, cpoint);}
else ai_move(table, os);
win = test_win(table, turn);
if (win == 1){
print_table(table, 0);
win_message(turn);
}
if (turn == 1){turn = 2;}
else if (turn == 2){turn = 1;}
}
free(table);
free(xs);
free(os);
free(cpoint);
}
int main(){
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
curs_set(0);
menu();
endwin();
return 0;
}