From 5ad8fa1534676ba1b8ce3776a5065be25e45696c Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Fri, 21 Feb 2025 06:38:24 -0500 Subject: [PATCH] Misdeal detection --- game.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/game.c b/game.c index 0498361..2f42941 100644 --- a/game.c +++ b/game.c @@ -272,6 +272,19 @@ void run_frame_initializing(Game *g) { g->state = GAME_STATE_DEALING; } +bool misdeal(Game *g) { + int month_count[12] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; + for (int i = 0; i < g->field.count; i++) { + Card *c = g->field.cards[i]; + month_count[c->month]++; + } + + for (int i = 0; i < 12; i++) + if (month_count[i] >= 4) return true; + + return false; +} + void run_frame_dealing(Game *g) { if (g->player.hand.count < 4) { deal(&g->deck, &g->player.hand, 4, true); @@ -290,8 +303,12 @@ void run_frame_dealing(Game *g) { } else if (g->field.count < 6) { deal(&g->deck, &g->field, 3, true); } else { - // TODO: check for misdeals - g->state = GAME_STATE_CALCULATING_FIELD_MULTIPLIER; + if (misdeal(g)) { + printf("misdeal\n"); + g->state = GAME_STATE_INITIALIZING; + } else { + g->state = GAME_STATE_CALCULATING_FIELD_MULTIPLIER; + } } }