mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
feat[lib]: validate action partial implementation
Performed most checks. Added placeholders to functions called.
This commit is contained in:
parent
b5bebbdd32
commit
ee12e48a86
48
src/lib.cpp
48
src/lib.cpp
@ -1,7 +1,18 @@
|
|||||||
|
#include "lib.hh"
|
||||||
|
|
||||||
#include "prep/prep.hh"
|
#include "prep/prep.hh"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
enum VALIDATION_STATUS {
|
||||||
|
NO_PLAYER,
|
||||||
|
ROOM_NOT_IN_PROGRESS,
|
||||||
|
ACTION_PROHIBITED,
|
||||||
|
ACTION_NOT_ALLOWED,
|
||||||
|
NO_ROLE,
|
||||||
|
ACTION_VALID,
|
||||||
|
};
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS);
|
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS);
|
||||||
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED);
|
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED);
|
||||||
@ -10,19 +21,40 @@ void run() {
|
|||||||
Role role2(actions);
|
Role role2(actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum VALIDATION_STATUS {
|
|
||||||
NO_PLAYER,
|
|
||||||
ROOM_NOT_IN_PROGRESS,
|
|
||||||
ACTION_PROHIBITED,
|
|
||||||
ACTION_NOT_ALLOWED,
|
|
||||||
ACTION_VALID,
|
|
||||||
};
|
|
||||||
|
|
||||||
int validateAction(
|
int validateAction(
|
||||||
Player *actor, Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr) {
|
Player *actor, Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr) {
|
||||||
|
if (!actor) {
|
||||||
|
return NO_PLAYER;
|
||||||
|
}
|
||||||
|
// TODO: Check if action has a target
|
||||||
|
if (room->status != RoomStatus::IN_PROGRESS) {
|
||||||
|
return ROOM_NOT_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
Role *role = &actor->role;
|
||||||
|
if (!role) {
|
||||||
|
return NO_ROLE;
|
||||||
|
}
|
||||||
|
if (!actionBelongsToRole(role, action)) {
|
||||||
|
return ACTION_NOT_ALLOWED;
|
||||||
|
}
|
||||||
|
if (!isActionAllowed(relatedEvents)) {
|
||||||
|
return ACTION_PROHIBITED;
|
||||||
|
}
|
||||||
return ACTION_VALID;
|
return ACTION_VALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool actionBelongsToRole(Role *role, Action *action) {
|
||||||
|
// TODO: implement
|
||||||
|
bool belongs = false;
|
||||||
|
return belongs;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isActionAllowed(std::vector<Event> *relevantEvents) {
|
||||||
|
// TODO: implement
|
||||||
|
bool allowed = false;
|
||||||
|
return allowed;
|
||||||
|
}
|
||||||
|
|
||||||
int functionToTest(int a) {
|
int functionToTest(int a) {
|
||||||
return a * 2;
|
return a * 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#include "prep/prep.hh"
|
#include "prep/prep.hh"
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
int validateAction(
|
|
||||||
Player *actor, Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr);
|
bool actionBelongsToRole(Role *role, Action *action);
|
||||||
|
bool isActionAllowed(std::vector<Event> *relevantEvents);
|
||||||
|
int validateAction(Player *actor, Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target);
|
||||||
int functionToTest(int);
|
int functionToTest(int);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user