-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.c
46 lines (39 loc) · 1.24 KB
/
stats.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
#include "stats.h"
#include "utils.h"
Stats* alloc_stats() {
Stats* stats = malloc(sizeof(Stats));
stats->bricksNonZero = furi_string_alloc();
return stats;
}
void free_stats(Stats* stats) {
furi_string_free(stats->bricksNonZero);
free(stats);
}
void update_board_stats(PlayGround* pg, Stats* stats) {
memset(stats->ofBrick, '\0', sizeof(stats->ofBrick));
char buff[2];
memset(buff, '\0', sizeof(buff));
uint8_t x, y, i, tile;
for(y = 0; y < SIZE_Y; y++) {
for(x = 0; x < SIZE_X; x++) {
tile = (*pg)[y][x];
if(is_block(tile)) {
stats->ofBrick[tile]++;
}
}
}
memset(stats->statsNonZero, 0, sizeof(stats->statsNonZero));
furi_string_reset(stats->bricksNonZero);
for(i = 0; i < WALL_TILE; i++) {
if(stats->ofBrick[i] > 0) {
buff[0] = i;
furi_string_cat_str(stats->bricksNonZero, buff);
stats->statsNonZero[furi_string_size(stats->bricksNonZero) - 1] = stats->ofBrick[i];
}
}
FURI_LOG_D(
TAG,
"Stats, bricks [%s] counts [%s]",
furi_string_get_cstr(stats->bricksNonZero),
(const char*)stats->statsNonZero);
}