More idiomatic calculation
This commit is contained in:
parent
5e0109a9b6
commit
37bb1b47d0
12
main.c
12
main.c
@ -71,8 +71,10 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
// float delta;
|
// float delta;
|
||||||
Vector2 mouse_pos;
|
Vector2 mouse_pos;
|
||||||
char *teyaku_calculation = "";
|
char teyaku_calculation[400];
|
||||||
|
strcpy(teyaku_calculation, "");
|
||||||
char dekiyaku_calculation[400];
|
char dekiyaku_calculation[400];
|
||||||
|
strcpy(dekiyaku_calculation, "");
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
// delta = GetFrameTime();
|
// delta = GetFrameTime();
|
||||||
@ -82,7 +84,7 @@ int main(int argc, char** argv) {
|
|||||||
for (int i = 0; i < 48; i++) {
|
for (int i = 0; i < 48; i++) {
|
||||||
if (point_within_card(&cards[i], mouse_pos)) {
|
if (point_within_card(&cards[i], mouse_pos)) {
|
||||||
cards[i].selected = !cards[i].selected;
|
cards[i].selected = !cards[i].selected;
|
||||||
teyaku_calculation = "";
|
strcpy(teyaku_calculation, "");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,9 +106,11 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (num_selected == 7) {
|
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 {
|
} else {
|
||||||
teyaku_calculation = "";
|
strcpy(teyaku_calculation, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
Dekiyaku d;
|
Dekiyaku d;
|
||||||
|
27
teyaku.c
27
teyaku.c
@ -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 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" };
|
static char *chaff_teyaku_english_array[6] = { "None", "Red", "One Ribbon", "One Animal", "One Bright", "Empty Hand" };
|
||||||
|
|
||||||
int set_teyaku_points(const Hand h) {
|
int set_teyaku_points(SetTeyaku st) {
|
||||||
return set_teyaku_points_array[calculate_set_teyaku(h)];
|
return set_teyaku_points_array[st];
|
||||||
}
|
}
|
||||||
|
|
||||||
int chaff_teyaku_points(const Hand h) {
|
int chaff_teyaku_points(ChaffTeyaku ct) {
|
||||||
return chaff_teyaku_points_array[calculate_chaff_teyaku(h)];
|
return chaff_teyaku_points_array[ct];
|
||||||
}
|
}
|
||||||
|
|
||||||
char *set_teyaku_english(const Hand h) {
|
char *set_teyaku_english(SetTeyaku st) {
|
||||||
return set_teyaku_english_array[calculate_set_teyaku(h)];
|
return set_teyaku_english_array[st];
|
||||||
}
|
}
|
||||||
|
|
||||||
char *chaff_teyaku_english(const Hand h) {
|
char *chaff_teyaku_english(ChaffTeyaku ct) {
|
||||||
return chaff_teyaku_english_array[calculate_chaff_teyaku(h)];
|
return chaff_teyaku_english_array[ct];
|
||||||
}
|
}
|
||||||
|
|
||||||
int calculate_teyaku(const Hand h) {
|
void calculate_teyaku(const Hand h, Teyaku *t) {
|
||||||
return chaff_teyaku_points(h) + set_teyaku_points(h);
|
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);
|
||||||
}
|
}
|
||||||
|
18
teyaku.h
18
teyaku.h
@ -4,7 +4,7 @@
|
|||||||
#include "card.h"
|
#include "card.h"
|
||||||
|
|
||||||
typedef enum SetTeyaku {
|
typedef enum SetTeyaku {
|
||||||
SET_TEYAKU_NONE = 0,
|
SET_TEYAKU_NONE,
|
||||||
TRIPLET,
|
TRIPLET,
|
||||||
STANDING_TRIPLET,
|
STANDING_TRIPLET,
|
||||||
TWO_TRIPLETS,
|
TWO_TRIPLETS,
|
||||||
@ -18,7 +18,7 @@ typedef enum SetTeyaku {
|
|||||||
} SetTeyaku;
|
} SetTeyaku;
|
||||||
|
|
||||||
typedef enum ChaffTeyaku {
|
typedef enum ChaffTeyaku {
|
||||||
CHAFF_TEYAKU_NONE = 0,
|
CHAFF_TEYAKU_NONE,
|
||||||
CHAFF_TEYAKU_RED,
|
CHAFF_TEYAKU_RED,
|
||||||
ONE_RIBBON,
|
ONE_RIBBON,
|
||||||
ONE_ANIMAL,
|
ONE_ANIMAL,
|
||||||
@ -26,12 +26,12 @@ typedef enum ChaffTeyaku {
|
|||||||
EMPTY_HAND,
|
EMPTY_HAND,
|
||||||
} ChaffTeyaku;
|
} ChaffTeyaku;
|
||||||
|
|
||||||
int calculate_teyaku(const Hand h);
|
typedef struct Teyaku {
|
||||||
SetTeyaku calculate_set_teyaku(const Hand h);
|
ChaffTeyaku chaff;
|
||||||
ChaffTeyaku calculate_chaff_teyaku(const Hand h);
|
SetTeyaku set;
|
||||||
char *set_teyaku_english(const Hand h);
|
} Teyaku;
|
||||||
char *chaff_teyaku_english(const Hand h);
|
|
||||||
int set_teyaku_points(const Hand h);
|
void calculate_teyaku(const Hand h, Teyaku *t);
|
||||||
int chaff_teyaku_points(const Hand h);
|
void teyaku_to_string(Teyaku *t, char *str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user