-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.c
More file actions
55 lines (49 loc) · 1.58 KB
/
tempCodeRunnerFile.c
File metadata and controls
55 lines (49 loc) · 1.58 KB
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
void GetMoveBot1(int board[MAX_SIZE][MAX_SIZE], int size, int player, char *side, int *move)
{
char sides[] = {'T', 'B', 'L', 'R'};
// Check for winning moves
for (int s = 0; s < 4; s++) {
for (int m = 0; m < size; m++) {
// Check if move is valid first
if (sides[s] == 'T' && board[0][m] != 0) continue;
if (sides[s] == 'B' && board[size-1][m] != 0) continue;
if (sides[s] == 'L' && board[m][0] != 0) continue;
if (sides[s] == 'R' && board[m][size-1] != 0) continue;
// Create a temporary board to test the move
int temp_board[MAX_SIZE][MAX_SIZE];
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
temp_board[i][j] = board[i][j];
}
}
// Try the move
PopIn(temp_board, size, sides[s], m, player);
// Check if this move wins
if (CheckGameOver(temp_board, size) == player) {
*side = sides[s];
*move = m;
return;
}
}
}
// If no winning move, use strategy of filling bottom row first
*side = 'T';
if(board[size-1][3] == 0){
*move = 3;
}
else if(board[size-1][2] == 0){
*move = 2;
}
else if(board[size-1][4] == 0){
*move = 4;
}
else if(board[size-1][1] == 0){
*move = 1;
}
else if(board[size-1][5] == 0){
*move = 5;
}
else{
*move = rand() % size;
}
}