-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
69 lines (66 loc) · 1.51 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
#include <stdlib.h>
#include <stdio.h>
#include "minesweeper.h"
#include "AI.h"
#define MAX_X 5
#define MAX_Y 5
#define MAX_MINES 2
int main(int argc, char **argv)
{
int x = MAX_X;
int y = MAX_Y;
int mines = MAX_MINES;
// printf("%d %d %d\n\n", x, y, mines);
if(argc==1) {
struct Board *board = init_board(x, y, mines);
init_AI(x, y, mines);
int game=0;
struct Point target;
while (game >= 0) {
print_board(board);
printf("\n");
print_AI_grid();
printf("Target?");
target = AI_get_target();
printf("\nTargetting: %d %d\n", target.x, target.y);
game = shoot(board, target.x, target.y);
printf("Result: %d \n\n",game);
AI_send_result(target.x, target.y, game);
}
printf("\n");
if(game==-1)
printf("LOST\n");
else if(game==-2)
printf("WON\n");
free_board(board);
free_AI();
}
else {
int total=atoi(argv[1]);
int i;
int won=0;
int last_percent=0, percent=0;
for(i=0;i<total;i++) {
struct Board *board = init_board(x, y, mines);
init_AI(x, y, mines);
int game=0;
struct Point target;
while (game >= 0) {
target = AI_get_target();
game = shoot(board, target.x, target.y);
AI_send_result(target.x, target.y, game);
}
if(game==-2)
won++;
free_board(board);
free_AI();
percent = (int)((float)i/total*100);
if(last_percent < percent) {
printf("%d percent done, ratio: %f \n", percent, (float)won/(i+1));
last_percent = percent;
}
}
printf("Won %d out of %d\nRatio: %f \n", won, total, (float)won/total);
}
return 0;
}