2025-02-01 11:12:07 -05:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2025-02-01 11:05:46 -05:00
|
|
|
#include "dekiyaku.h"
|
|
|
|
|
|
|
|
void calculate_dekiyaku(const Hand h, Dekiyaku *d) {
|
|
|
|
int brights = 0, ribbons = 0, ribbons_except_november = 0, blue_ribbons = 0, poetry_ribbons = 0, boar = 0, deer = 0, butterflies = 0;
|
|
|
|
for (int i = 0; i < h.count; i++) {
|
2025-02-02 18:13:19 -05:00
|
|
|
Card *card = h.cards[i];
|
|
|
|
switch (card->type) {
|
2025-02-01 11:05:46 -05:00
|
|
|
case BRIGHT: brights++; break;
|
|
|
|
case RIBBON:
|
|
|
|
ribbons++;
|
2025-02-02 18:13:19 -05:00
|
|
|
if (card->month != NOVEMBER) ribbons_except_november++;
|
|
|
|
switch (card->ribbon_type) {
|
2025-02-01 11:05:46 -05:00
|
|
|
case RIBBON_BLUE: blue_ribbons++; break;
|
|
|
|
case RIBBON_POETRY: poetry_ribbons++; break;
|
2025-02-01 11:12:07 -05:00
|
|
|
default: break;
|
2025-02-01 11:05:46 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ANIMAL:
|
2025-02-02 18:13:19 -05:00
|
|
|
switch (card->month) {
|
2025-02-01 11:05:46 -05:00
|
|
|
case JUNE: butterflies++; break;
|
|
|
|
case JULY: boar++; break;
|
|
|
|
case OCTOBER: deer++; break;
|
2025-02-01 11:12:07 -05:00
|
|
|
default: break;
|
2025-02-01 11:05:46 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CHAFF:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d->count = 0;
|
|
|
|
|
|
|
|
if (brights == 5) {
|
|
|
|
d->meld[d->count].type = FIVE_BRIGHTS;
|
|
|
|
d->meld[d->count].value = 12;
|
|
|
|
d->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (brights == 4) {
|
|
|
|
d->meld[d->count].type = FOUR_BRIGHTS;
|
|
|
|
d->meld[d->count].value = 10;
|
|
|
|
d->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ribbons_except_november >= 7) {
|
|
|
|
d->meld[d->count].type = SEVEN_RIBBONS;
|
|
|
|
d->meld[d->count].value = 3 + ribbons; // Include november ribbons in this count
|
|
|
|
d->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (poetry_ribbons == 3) {
|
|
|
|
d->meld[d->count].type = POETRY_RIBBONS;
|
|
|
|
d->meld[d->count].value = 7;
|
|
|
|
d->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blue_ribbons == 3) {
|
|
|
|
d->meld[d->count].type = BLUE_RIBBONS;
|
|
|
|
d->meld[d->count].value = 7;
|
|
|
|
d->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boar == 1 && deer == 1 && butterflies == 1) {
|
|
|
|
d->meld[d->count].type = BOAR_DEER_BUTTERFLIES;
|
|
|
|
d->meld[d->count].value = 7;
|
|
|
|
d->count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *meld_name(DekiyakuMeldType d) {
|
|
|
|
switch (d) {
|
|
|
|
case FIVE_BRIGHTS:
|
|
|
|
return "5B";
|
|
|
|
case FOUR_BRIGHTS:
|
|
|
|
return "4B";
|
|
|
|
case SEVEN_RIBBONS:
|
|
|
|
return "7R";
|
|
|
|
case POETRY_RIBBONS:
|
|
|
|
return "PS";
|
|
|
|
case BLUE_RIBBONS:
|
|
|
|
return "BS";
|
|
|
|
case BOAR_DEER_BUTTERFLIES:
|
|
|
|
return "ISK";
|
2025-02-01 11:12:07 -05:00
|
|
|
default:
|
|
|
|
return "None";
|
2025-02-01 11:05:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int dekiyaku_value(Dekiyaku *d) {
|
|
|
|
int value = 0;
|
|
|
|
for (int i = 0; i < d->count; i++) {
|
|
|
|
value += d->meld[i].value;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dekiyaku_to_string(Dekiyaku *d, char *str) {
|
|
|
|
char meld_str[200];
|
|
|
|
|
|
|
|
strcpy(str, "Dekiyaku: ");
|
|
|
|
for (int i = 0; i < d->count; i++) {
|
|
|
|
sprintf(meld_str, "%s (%d) + ", meld_name(d->meld[i].type), d->meld[i].value);
|
|
|
|
strcat(str, meld_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->count == 0) strcat(str, "none (0)");
|
|
|
|
else {
|
|
|
|
str[strlen(str) - 2] = '=';
|
|
|
|
sprintf(meld_str, "%d", dekiyaku_value(d));
|
|
|
|
strcat(str, meld_str);
|
|
|
|
}
|
|
|
|
}
|