-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
142 lines (117 loc) · 2.13 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "ai_header.h"
int main(void)
{
//Uusr = 1
//AI = 2
//Empty = 0
int **map = NULL;
int i, k;
map = (int**)malloc(sizeof(int*) * 6);
for (i = 0; i < 6; i++)
{
map[i] = (int*)malloc(sizeof(int) * 7);
}
int decide_exit = 100;
int first;
int user_turn_x;
int regame;
while (1)
{
for (i = 0; i < 6; i++)
{
for (k = 0; k < 7; k++)
map[i][k] = 0;
}
printf("Who start first? 1 -> user 2 -> AI\n");
scanf("%d", &first);
print_map(map);
if (first == 1)
{
while (1)
{
printf("inert location x : ");
scanf("%d", &user_turn_x);
user_select(map, --user_turn_x);
print_map(map);
decide_exit = decide_win_or_lose_or_continue(map);
if (decide_exit == USERWIN)
{
printf("User Win!\n");
break;
}
else if (decide_exit == AIWIN)
{
printf("AI Win!\n");
break;
}
ai_search_function(map);
print_map(map);
decide_exit = decide_win_or_lose_or_continue(map);
if (decide_exit == USERWIN)
{
printf("User Win!\n");
break;
}
else if (decide_exit == AIWIN)
{
printf("AI Win!\n");
break;
}
}
}
else if (first == 2)
{
while (1)
{
ai_search_function(map);
print_map(map);
decide_exit = decide_win_or_lose_or_continue(map);
if (decide_exit == USERWIN)
{
printf("User Win!\n");
break;
}
else if (decide_exit == AIWIN)
{
printf("AI Win!\n");
break;
}
printf("inert location x : ");
scanf("%d", &user_turn_x);
user_select(map, --user_turn_x);
print_map(map);
decide_exit = decide_win_or_lose_or_continue(map);
if (decide_exit == USERWIN)
{
printf("User Win!\n");
break;
}
else if (decide_exit == AIWIN)
{
printf("AI Win!\n");
break;
}
}
}
printf("\n");
printf("Do you want regame? 1 ok 2 no ");
scanf("%d", ®ame);
if (regame == 2)
return 0;
}
return 0;
}
void user_select(int **map, int number)
{
int i;
for (i = 0; i < 6; i++)
{
if (map[i][number] == 0)
{
map[i][number] = 1;
return;
}
if (i == 5)
printf("Wrong place!\n");
}
}