-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
68 lines (47 loc) · 1.24 KB
/
init.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
#include "head.h"
void init_grid(GRID * grid){
int s = (grid->size = get_size()), difficulty = get_difficulty(), i = 0, bomb_goal = 0, x = 0, y = 0;
CASE * this_case;
bomb_goal = pow(s, 2) * difficulty / 10;
grid->cases = malloc(s * sizeof(CASE *));
if (grid->cases == NULL) exit(0);
grid->nb_bombs = 0;
grid->nb_safe = pow(s, 2) - bomb_goal;
grid->nb_dug = 0;
grid->nb_marked = 0;
for (i = 0; i < s; i++){
grid->cases[i] = malloc(s * sizeof(CASE));
if (grid->cases[i] == NULL) exit(0);
}
while (grid->nb_bombs < bomb_goal){
x = (rand() % s + s) % s;
y = (rand() % s + s) % s;
this_case = &(grid->cases[y][x]);
if (!this_case->bomb){
this_case->bomb = true;
inc_values(grid, y, x);
grid->nb_bombs++;
}
}
}
void inc_values(GRID * grid, int y, int x){
int i = 0, j = 0;
for (i = y - 1; i <= y + 1; i++){
if (i >= 0 && i < grid->size){
for (j = x - 1; j <= x + 1; j++){
if (j >= 0 && j < grid->size){
grid->cases[i][j].neighbors++;
}
}
}
}
}
void init_file(char file_name[32]){
int i = 0;
struct tm time;
PLAYER blank = {.name = "", .time = time, .size = 0};
PLAYER ** noobs = malloc(10 * sizeof(PLAYER *));
for (i = 0; i < 10; i++)
noobs[i] = ␣
save(file_name, noobs);
}