hanafuda/play.c

27 lines
654 B
C
Raw Normal View History

2025-02-06 19:44:48 -05:00
#include <stddef.h>
#include <stdbool.h>
#include "play.h"
bool valid_play(Hand *field, Card *played, Card *target) {
if (target == NULL) {
bool matching_month_in_field = false;
for (int i = 0; i < field->count; i++) {
if (field->cards[i]->month == target->month) {
matching_month_in_field = true;
break;
}
}
return !matching_month_in_field;
} else {
bool target_in_field = false;
for (int i = 0; i < field->count; i++) {
if (field->cards[i]->index == target->index) {
target_in_field = true;
break;
}
}
if (!target_in_field) return false;
return played->month == target->month;
}
}