diff --git a/src/main.cc b/src/main.cc index bb76d4b..4aef986 100644 --- a/src/main.cc +++ b/src/main.cc @@ -19,6 +19,6 @@ int main(int argc, char *argv[]) { Room room2(2, "Room 2", 1710087384, RoomStatus::Ended, {}); ValidationStatus validated_action = validate_action(&player1, &kill, &room1, &relatedEvents, &player2); std::string validated_action_str = ValidationStatusUtils::to_string(validated_action); - printf("The action validation result is \"%s\"\n", validated_action_str.c_str()); + printf("The validation result is \"%s\"\n", validated_action_str.c_str()); return EXIT_SUCCESS; } diff --git a/src/modules/event.hh b/src/modules/event.hh index ae5cb78..675f538 100644 --- a/src/modules/event.hh +++ b/src/modules/event.hh @@ -8,7 +8,7 @@ #include #include -enum EventType { +enum class EventType { PhaseChange, EventAction, RoomStateChange, diff --git a/src/validation.cc b/src/validation.cc index 692c13f..2c73902 100644 --- a/src/validation.cc +++ b/src/validation.cc @@ -38,11 +38,12 @@ bool action_belongs_to_role(const Role *role, const Action *action) { * @param relevantEvents Pointer to the vector of relevant events. * @return `true` if the action is allowed, otherwise `false`. */ -bool is_action_allowed(const Action *action, const std::vector *relevant_events) { +bool is_action_allowed(const Action *action, std::vector *relevant_events) { bool allowed = false; // Actions are disabled by default + std::sort(relevant_events->begin(), relevant_events->end()); for (const auto &event : *relevant_events) { if (std::find(event.prohibits.begin(), event.prohibits.end(), *action) != event.prohibits.end()) { - return false; // If action is prohibited, return false immediately + allowed = false; } if (std::find(event.allows.begin(), event.allows.end(), *action) != event.allows.end()) { allowed = true; @@ -94,7 +95,7 @@ ValidationStatus validate_action( if (!is_action_allowed(action, related_events)) { return ValidationStatus::ActionProhibited; } - return ValidationStatus::ActionProhibited; + return ValidationStatus::ActionValid; } std::string ValidationStatusUtils::to_string(ValidationStatus status) {