#include "card.h" int 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 for (int i = 0; i < h.count; i++) { Card c = h.cards[i]; month_counts[c.month]++; } int triplets = 0, standing_triplets = 0, pairs = 0, four_of_a_kind = 0; for (int i = 0; i < 12; i++) { if (month_counts[i] == 4) { four_of_a_kind++; } else if (month_counts[i] == 3) { if (month_stands[i]) standing_triplets++; else triplets++; } else if (month_counts[i] == 2) { pairs++; } } 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; // 三本 return 0; } int calculate_chaff_teyaku(Hand h) { int ribbons = 0; int animals = 0; int brights = 0; int chaff = 0; for (int i = 0; i < h.count; i++) { Card c = h.cards[i]; if (c.month == NOVEMBER) chaff++; // November cards are all counted as chaff here else if (c.type == BRIGHT) brights++; else if (c.type == RIBBON) ribbons++; else if (c.type == ANIMAL) animals++; 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; } int calculate_teyaku(Hand h) { return calculate_chaff_teyaku(h) + calculate_set_teyaku(h); }