forked from voldemortX/hex_platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hex_random_ai.c
97 lines (88 loc) · 1.3 KB
/
hex_random_ai.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
#include<stdio.h>
#include<stdlib.h>
#define RED 0
#define BLUE 1
int board[11][11] = {0};
char cmd[256];
char response[256];
int color = 0;
void get_move(char* cmd)
{
int x,y;
x = cmd[0] - 'A';
y = cmd[1] - 'A';
board[x][y] = (!color)+1;
}
void make_move(char* response)
{
//randomly choose a move
srand(time(0));
int x,y;
do
{
x = rand()%11;
y = rand()%11;
}while(board[x][y]!=0);
board[x][y] = color+1;
response[0] = x+'A';
response[1] = y+'A';
response[2] = '\0';
}
int main()
{
while(1)
{
//Get command
scanf("%s",cmd);
//return name
if(!strcmp(cmd,"name?"))
{
fflush(stdin);
printf("name Test\n");
fflush(stdout);
continue;
}
//exit
if(!strcmp(cmd,"exit"))
{
fflush(stdin);
exit(0);
}
//wrong command
if(!strcmp(cmd,"wrong"))
{
fflush(stdin);
continue;
}
//start
if(!strcmp(cmd,"start"))
{
scanf("%s",cmd);
//fflush(stdin);
//Red
if(!strcmp(cmd,"red"))
{
color = RED;
make_move(response);
printf("move %s\n",response );
fflush(stdout);
}
else//Blue
{
color = BLUE;
}
continue;
}
//make move
if(!strcmp(cmd,"move"))
{
scanf("%s",cmd);
fflush(stdin);
get_move(cmd);
make_move(response);
printf("move %s\n",response);
fflush(stdout);
continue;
}
}
}