mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
fix: invalid validation result
This commit is contained in:
parent
e316beedbc
commit
72b89de4ce
@ -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;
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum EventType {
|
||||
enum class EventType {
|
||||
PhaseChange,
|
||||
EventAction,
|
||||
RoomStateChange,
|
||||
|
||||
@ -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<Event> *relevant_events) {
|
||||
bool is_action_allowed(const Action *action, std::vector<Event> *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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user