stats.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "stats.h"
  2. #include "utils.h"
  3. Stats* alloc_stats() {
  4. Stats* stats = malloc(sizeof(Stats));
  5. stats->bricksNonZero = furi_string_alloc();
  6. return stats;
  7. }
  8. void free_stats(Stats* stats) {
  9. furi_string_free(stats->bricksNonZero);
  10. free(stats);
  11. }
  12. void update_board_stats(PlayGround* pg, Stats* stats) {
  13. memset(stats->ofBrick, '\0', sizeof(stats->ofBrick));
  14. char buff[2];
  15. memset(buff, '\0', sizeof(buff));
  16. uint8_t x, y, i, tile;
  17. for(y = 0; y < SIZE_Y; y++) {
  18. for(x = 0; x < SIZE_X; x++) {
  19. tile = (*pg)[y][x];
  20. if(is_block(tile)) {
  21. stats->ofBrick[tile]++;
  22. }
  23. }
  24. }
  25. memset(stats->statsNonZero, 0, sizeof(stats->statsNonZero));
  26. furi_string_reset(stats->bricksNonZero);
  27. for(i = 0; i < WALL_TILE; i++) {
  28. if(stats->ofBrick[i] > 0) {
  29. buff[0] = i;
  30. furi_string_cat_str(stats->bricksNonZero, buff);
  31. stats->statsNonZero[furi_string_size(stats->bricksNonZero) - 1] = stats->ofBrick[i];
  32. }
  33. }
  34. FURI_LOG_D(
  35. TAG,
  36. "Stats, bricks [%s] counts [%s]",
  37. furi_string_get_cstr(stats->bricksNonZero),
  38. (const char*)stats->statsNonZero);
  39. }