More idiomatic calculation

This commit is contained in:
Bill Rossi 2025-02-01 11:23:01 -05:00
parent 5e0109a9b6
commit 37bb1b47d0
3 changed files with 34 additions and 23 deletions

12
main.c
View File

@ -71,8 +71,10 @@ int main(int argc, char** argv) {
// float delta;
Vector2 mouse_pos;
char *teyaku_calculation = "";
char teyaku_calculation[400];
strcpy(teyaku_calculation, "");
char dekiyaku_calculation[400];
strcpy(dekiyaku_calculation, "");
while (!WindowShouldClose()) {
// delta = GetFrameTime();
@ -82,7 +84,7 @@ int main(int argc, char** argv) {
for (int i = 0; i < 48; i++) {
if (point_within_card(&cards[i], mouse_pos)) {
cards[i].selected = !cards[i].selected;
teyaku_calculation = "";
strcpy(teyaku_calculation, "");
break;
}
}
@ -104,9 +106,11 @@ int main(int argc, char** argv) {
}
if (num_selected == 7) {
teyaku_calculation = TextFormat("Set: %s(%d) / Chaff: %s(%d) / Total: %d", set_teyaku_english(h), set_teyaku_points(h), chaff_teyaku_english(h), chaff_teyaku_points(h), calculate_teyaku(h));
Teyaku t;
calculate_teyaku(h, &t);
teyaku_to_string(&t, teyaku_calculation);
} else {
teyaku_calculation = "";
strcpy(teyaku_calculation, "");
}
Dekiyaku d;

View File

@ -67,22 +67,29 @@ static char *set_teyaku_english_array[11] = { "None", "Triplet", "Standing Tripl
static int chaff_teyaku_points_array[6] = { 0, 2, 3, 3, 4, 4 };
static char *chaff_teyaku_english_array[6] = { "None", "Red", "One Ribbon", "One Animal", "One Bright", "Empty Hand" };
int set_teyaku_points(const Hand h) {
return set_teyaku_points_array[calculate_set_teyaku(h)];
int set_teyaku_points(SetTeyaku st) {
return set_teyaku_points_array[st];
}
int chaff_teyaku_points(const Hand h) {
return chaff_teyaku_points_array[calculate_chaff_teyaku(h)];
int chaff_teyaku_points(ChaffTeyaku ct) {
return chaff_teyaku_points_array[ct];
}
char *set_teyaku_english(const Hand h) {
return set_teyaku_english_array[calculate_set_teyaku(h)];
char *set_teyaku_english(SetTeyaku st) {
return set_teyaku_english_array[st];
}
char *chaff_teyaku_english(const Hand h) {
return chaff_teyaku_english_array[calculate_chaff_teyaku(h)];
char *chaff_teyaku_english(ChaffTeyaku ct) {
return chaff_teyaku_english_array[ct];
}
int calculate_teyaku(const Hand h) {
return chaff_teyaku_points(h) + set_teyaku_points(h);
void calculate_teyaku(const Hand h, Teyaku *t) {
t->chaff = calculate_chaff_teyaku(h);
t->set = calculate_set_teyaku(h);
}
void teyaku_to_string(Teyaku *t, char *str) {
int set_points = set_teyaku_points(t->set);
int chaff_points = chaff_teyaku_points(t->chaff);
sprintf(str, "Set: %s(%d) / Chaff: %s(%d) / Total: %d", set_teyaku_english(t->set), set_points, chaff_teyaku_english(t->chaff), chaff_points, set_points + chaff_points);
}

View File

@ -4,7 +4,7 @@
#include "card.h"
typedef enum SetTeyaku {
SET_TEYAKU_NONE = 0,
SET_TEYAKU_NONE,
TRIPLET,
STANDING_TRIPLET,
TWO_TRIPLETS,
@ -18,7 +18,7 @@ typedef enum SetTeyaku {
} SetTeyaku;
typedef enum ChaffTeyaku {
CHAFF_TEYAKU_NONE = 0,
CHAFF_TEYAKU_NONE,
CHAFF_TEYAKU_RED,
ONE_RIBBON,
ONE_ANIMAL,
@ -26,12 +26,12 @@ typedef enum ChaffTeyaku {
EMPTY_HAND,
} ChaffTeyaku;
int calculate_teyaku(const Hand h);
SetTeyaku calculate_set_teyaku(const Hand h);
ChaffTeyaku calculate_chaff_teyaku(const Hand h);
char *set_teyaku_english(const Hand h);
char *chaff_teyaku_english(const Hand h);
int set_teyaku_points(const Hand h);
int chaff_teyaku_points(const Hand h);
typedef struct Teyaku {
ChaffTeyaku chaff;
SetTeyaku set;
} Teyaku;
void calculate_teyaku(const Hand h, Teyaku *t);
void teyaku_to_string(Teyaku *t, char *str);
#endif