Let's be nice and use consts

This commit is contained in:
Bill Rossi 2025-02-01 08:32:38 -05:00
parent a40067ff8f
commit c402ea7140
2 changed files with 14 additions and 14 deletions

View File

@ -3,7 +3,7 @@
#include "teyaku.h" #include "teyaku.h"
#include "card.h" #include "card.h"
SetTeyaku calculate_set_teyaku(Hand h) { SetTeyaku calculate_set_teyaku(const Hand h) {
int month_counts[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int month_counts[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int month_stands[12] = { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1 }; int month_stands[12] = { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1 };
for (int i = 0; i < h.count; i++) { for (int i = 0; i < h.count; i++) {
@ -38,7 +38,7 @@ SetTeyaku calculate_set_teyaku(Hand h) {
return SET_TEYAKU_NONE; return SET_TEYAKU_NONE;
} }
ChaffTeyaku calculate_chaff_teyaku(Hand h) { ChaffTeyaku calculate_chaff_teyaku(const Hand h) {
int ribbons = 0; int ribbons = 0;
int animals = 0; int animals = 0;
int brights = 0; int brights = 0;
@ -67,22 +67,22 @@ 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(Hand h) { int set_teyaku_points(const Hand h) {
return set_teyaku_points_array[calculate_set_teyaku(h)]; return set_teyaku_points_array[calculate_set_teyaku(h)];
} }
int chaff_teyaku_points(Hand h) { int chaff_teyaku_points(const Hand h) {
return chaff_teyaku_points_array[calculate_chaff_teyaku(h)]; return chaff_teyaku_points_array[calculate_chaff_teyaku(h)];
} }
char *set_teyaku_english(Hand h) { char *set_teyaku_english(const Hand h) {
return set_teyaku_english_array[calculate_set_teyaku(h)]; return set_teyaku_english_array[calculate_set_teyaku(h)];
} }
char *chaff_teyaku_english(Hand h) { char *chaff_teyaku_english(const Hand h) {
return chaff_teyaku_english_array[calculate_chaff_teyaku(h)]; return chaff_teyaku_english_array[calculate_chaff_teyaku(h)];
} }
int calculate_teyaku(Hand h) { int calculate_teyaku(const Hand h) {
return chaff_teyaku_points(h) + set_teyaku_points(h); return chaff_teyaku_points(h) + set_teyaku_points(h);
} }

View File

@ -26,12 +26,12 @@ typedef enum ChaffTeyaku {
EMPTY_HAND, EMPTY_HAND,
} ChaffTeyaku; } ChaffTeyaku;
int calculate_teyaku(Hand h); int calculate_teyaku(const Hand h);
SetTeyaku calculate_set_teyaku(Hand h); SetTeyaku calculate_set_teyaku(const Hand h);
ChaffTeyaku calculate_chaff_teyaku(Hand h); ChaffTeyaku calculate_chaff_teyaku(const Hand h);
char *set_teyaku_english(Hand h); char *set_teyaku_english(const Hand h);
char *chaff_teyaku_english(Hand h); char *chaff_teyaku_english(const Hand h);
int set_teyaku_points(Hand h); int set_teyaku_points(const Hand h);
int chaff_teyaku_points(Hand h); int chaff_teyaku_points(const Hand h);
#endif #endif