72 lines
1.6 KiB
C
72 lines
1.6 KiB
C
#include "tarot_logic.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include "esp_random.h"
|
|
|
|
static const char *const s_spread_3[] = {
|
|
"Past",
|
|
"Present",
|
|
"Future",
|
|
};
|
|
|
|
static const char *const s_spread_8[] = {
|
|
"Current energy",
|
|
"Challenge",
|
|
"Hidden influence",
|
|
"Past root",
|
|
"Near future",
|
|
"Advice",
|
|
"External energy",
|
|
"Outcome",
|
|
};
|
|
|
|
const char *tarot_spread_name(tarot_spread_t spread)
|
|
{
|
|
switch (spread) {
|
|
case TAROT_SPREAD_3_CARD:
|
|
return "3-card";
|
|
case TAROT_SPREAD_8_CARD:
|
|
return "8-card";
|
|
default:
|
|
return "Unknown";
|
|
}
|
|
}
|
|
|
|
const char *tarot_spread_position_meaning(tarot_spread_t spread, size_t index)
|
|
{
|
|
if (spread == TAROT_SPREAD_3_CARD && index < 3) {
|
|
return s_spread_3[index];
|
|
}
|
|
if (spread == TAROT_SPREAD_8_CARD && index < 8) {
|
|
return s_spread_8[index];
|
|
}
|
|
return "";
|
|
}
|
|
|
|
void tarot_logic_draw_reading(tarot_reading_t *reading, tarot_spread_t spread, bool reversed_enabled)
|
|
{
|
|
bool used[TAROT_DECK_SIZE] = { false };
|
|
size_t count = spread == TAROT_SPREAD_3_CARD ? 3 : 8;
|
|
|
|
if (reading == NULL) {
|
|
return;
|
|
}
|
|
|
|
memset(reading, 0, sizeof(*reading));
|
|
reading->spread = spread;
|
|
reading->count = count;
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
uint8_t card_id = 0;
|
|
do {
|
|
card_id = esp_random() % TAROT_DECK_SIZE;
|
|
} while (used[card_id]);
|
|
|
|
used[card_id] = true;
|
|
reading->cards[i].card = &tarot_deck[card_id];
|
|
reading->cards[i].reversed = reversed_enabled ? ((esp_random() & 1U) == 1U) : false;
|
|
reading->cards[i].position_meaning = tarot_spread_position_meaning(spread, i);
|
|
}
|
|
}
|