Misdeal detection
This commit is contained in:
parent
08823cc3b9
commit
5ad8fa1534
21
game.c
21
game.c
@ -272,6 +272,19 @@ void run_frame_initializing(Game *g) {
|
|||||||
g->state = GAME_STATE_DEALING;
|
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) {
|
void run_frame_dealing(Game *g) {
|
||||||
if (g->player.hand.count < 4) {
|
if (g->player.hand.count < 4) {
|
||||||
deal(&g->deck, &g->player.hand, 4, true);
|
deal(&g->deck, &g->player.hand, 4, true);
|
||||||
@ -290,8 +303,12 @@ void run_frame_dealing(Game *g) {
|
|||||||
} else if (g->field.count < 6) {
|
} else if (g->field.count < 6) {
|
||||||
deal(&g->deck, &g->field, 3, true);
|
deal(&g->deck, &g->field, 3, true);
|
||||||
} else {
|
} else {
|
||||||
// TODO: check for misdeals
|
if (misdeal(g)) {
|
||||||
g->state = GAME_STATE_CALCULATING_FIELD_MULTIPLIER;
|
printf("misdeal\n");
|
||||||
|
g->state = GAME_STATE_INITIALIZING;
|
||||||
|
} else {
|
||||||
|
g->state = GAME_STATE_CALCULATING_FIELD_MULTIPLIER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user