More ergonomic teyaku

This commit is contained in:
Bill Rossi 2025-02-01 07:04:28 -05:00
parent 58859768f0
commit 6375f1ec6f
3 changed files with 77 additions and 29 deletions

14
main.c
View File

@ -16,13 +16,13 @@ int main(int argc, char** argv) {
SetTargetFPS(60);
Hand h;
h.cards[0] = (Card) { 1, CHAFF, RIBBON_NONE, JANUARY, (Vector2) { 0, 0 } };
h.cards[1] = (Card) { 1, CHAFF, RIBBON_NONE, JANUARY, (Vector2) { 0, 0 } };
h.cards[2] = (Card) { 1, CHAFF, RIBBON_NONE, JANUARY, (Vector2) { 0, 0 } };
h.cards[3] = (Card) { 1, ANIMAL, RIBBON_NONE, JANUARY, (Vector2) { 0, 0 } };
h.cards[4] = (Card) { 1, ANIMAL, RIBBON_NONE, MAY, (Vector2) { 0, 0 } };
h.cards[5] = (Card) { 1, CHAFF, RIBBON_BLUE, MAY, (Vector2) { 0, 0 } };
h.cards[6] = (Card) { 1, CHAFF, RIBBON_PLAIN, MAY, (Vector2) { 0, 0 } };
h.cards[0] = (Card) { 1, BRIGHT, RIBBON_NONE, NOVEMBER, (Vector2) { 0, 0 } };
h.cards[1] = (Card) { 1, ANIMAL, RIBBON_NONE, NOVEMBER, (Vector2) { 0, 0 } };
h.cards[2] = (Card) { 1, RIBBON, RIBBON_PLAIN, NOVEMBER, (Vector2) { 0, 0 } };
h.cards[3] = (Card) { 1, CHAFF, RIBBON_NONE, NOVEMBER, (Vector2) { 0, 0 } };
h.cards[4] = (Card) { 1, CHAFF, RIBBON_NONE, DECEMBER, (Vector2) { 0, 0 } };
h.cards[5] = (Card) { 1, CHAFF, RIBBON_NONE, DECEMBER, (Vector2) { 0, 0 } };
h.cards[6] = (Card) { 1, CHAFF, RIBBON_NONE, DECEMBER, (Vector2) { 0, 0 } };
h.count = 7;
printf("Teyaku: %d\n", calculate_teyaku(h));

View File

@ -1,8 +1,9 @@
#include "teyaku.h"
#include "card.h"
int calculate_set_teyaku(Hand h) {
SetTeyaku calculate_set_teyaku(Hand h) {
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 }; // TODO Pawlonia is weird
int month_stands[12] = { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1 };
for (int i = 0; i < h.count; i++) {
Card c = h.cards[i];
month_counts[c.month]++;
@ -13,7 +14,7 @@ int calculate_set_teyaku(Hand h) {
if (month_counts[i] == 4) {
four_of_a_kind++;
} else if (month_counts[i] == 3) {
if (month_stands[i]) standing_triplets++;
if (month_stands[i]) standing_triplets++; // TODO Pawlonia is weird
else triplets++;
} else if (month_counts[i] == 2) {
pairs++;
@ -21,21 +22,21 @@ int calculate_set_teyaku(Hand h) {
}
int total_triplets = triplets + standing_triplets;
if (four_of_a_kind && total_triplets) return 20; // 四三
else if (four_of_a_kind && pairs) return 8; // 一二四
else if (standing_triplets == 2) return 8; // 二立三本
else if (total_triplets && pairs == 2) return 7; // 跳剣
else if (triplets == 1 && standing_triplets == 1) return 7; // 三本立三本
else if (four_of_a_kind) return 6; // 手四
else if (triplets == 2) return 6; // 二三本
else if (pairs == 3) return 4; // 二三本
else if (standing_triplets) return 3; // 立三本
else if (triplets) return 2; // 三本
if (four_of_a_kind && total_triplets) return FOUR_THREE;
else if (four_of_a_kind && pairs) return ONE_TWO_FOUR;
else if (standing_triplets == 2) return TWO_STANDING_TRIPLETS;
else if (total_triplets && pairs == 2) return TRIPLET_AND_TWO_PAIRS;
else if (triplets == 1 && standing_triplets == 1) return TRIPLET_AND_STANDING_TRIPLET;
else if (four_of_a_kind) return FOUR_OF_A_KIND;
else if (triplets == 2) return TWO_TRIPLETS;
else if (pairs == 3) return THREE_PAIRS;
else if (standing_triplets) return STANDING_TRIPLET;
else if (triplets) return TRIPLET;
return 0;
return SET_TEYAKU_NONE;
}
int calculate_chaff_teyaku(Hand h) {
ChaffTeyaku calculate_chaff_teyaku(Hand h) {
int ribbons = 0;
int animals = 0;
int brights = 0;
@ -50,14 +51,38 @@ int calculate_chaff_teyaku(Hand h) {
else chaff++;
}
if (chaff == 7) return 4; // 空素 - Empty Hand
else if (chaff == 6 && brights == 1) return 4; // 光一 - One Bright
else if (chaff == 6 && animals == 1) return 3; // 十一 - One Animal
else if (chaff == 6 && ribbons == 1) return 3; // 短一 - One Ribbon
else if (ribbons >= 2 && chaff == 7 - ribbons) return 2; // 赤 - Red
else return 0;
if (chaff == 7) return EMPTY_HAND;
else if (chaff == 6 && brights == 1) return ONE_BRIGHT;
else if (chaff == 6 && animals == 1) return ONE_ANIMAL;
else if (chaff == 6 && ribbons == 1) return ONE_RIBBON;
else if (ribbons >= 2 && chaff == 7 - ribbons) return CHAFF_TEYAKU_RED;
return CHAFF_TEYAKU_NONE;
}
static int set_teyaku_points_array[11] = { 0, 2, 3, 6, 7, 8, 4, 6, 7, 8, 20 };
static char *set_teyaku_english_array[11] = { "None", "Triplet", "Standing Triplet", "Two Triplets", "Triplet and Standing Triplet", "Two Standing Triplets", "Three Pairs", "Four of a Kind", "Triplet and Two Pairs", "One-Two-Four", "Four-Three" };
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(Hand h) {
return set_teyaku_points_array[calculate_set_teyaku(h)];
}
int chaff_teyaku_points(Hand h) {
return chaff_teyaku_points_array[calculate_chaff_teyaku(h)];
}
char *set_teyaku_english(Hand h) {
return set_teyaku_english_array[calculate_set_teyaku(h)];
}
char *chaff_teyaku_english(Hand h) {
return chaff_teyaku_english_array[calculate_chaff_teyaku(h)];
}
int calculate_teyaku(Hand h) {
return calculate_chaff_teyaku(h) + calculate_set_teyaku(h);
if (calculate_chaff_teyaku(h)) printf("%s\n", chaff_teyaku_english(h));
if (calculate_set_teyaku(h)) printf("%s\n", set_teyaku_english(h));
return chaff_teyaku_points(h) + set_teyaku_points(h);
}

View File

@ -3,6 +3,29 @@
#include "card.h"
typedef enum SetTeyaku {
SET_TEYAKU_NONE,
TRIPLET,
STANDING_TRIPLET,
TWO_TRIPLETS,
TRIPLET_AND_STANDING_TRIPLET,
TWO_STANDING_TRIPLETS,
THREE_PAIRS,
FOUR_OF_A_KIND,
TRIPLET_AND_TWO_PAIRS,
ONE_TWO_FOUR,
FOUR_THREE,
} SetTeyaku;
typedef enum ChaffTeyaku {
CHAFF_TEYAKU_NONE,
CHAFF_TEYAKU_RED,
ONE_RIBBON,
ONE_ANIMAL,
ONE_BRIGHT,
EMPTY_HAND,
} ChaffTeyaku;
int calculate_teyaku(Hand h);
#endif