mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
refactor: move run function to main
This commit is contained in:
parent
8e06b54380
commit
03933af4b2
18
src/lib.cpp
18
src/lib.cpp
@ -20,24 +20,6 @@ enum VALIDATION_STATUS {
|
|||||||
ACTION_VALID,
|
ACTION_VALID,
|
||||||
};
|
};
|
||||||
|
|
||||||
void run() {
|
|
||||||
const Action kill = Action("kill", true);
|
|
||||||
const Action heal = Action("heal", true);
|
|
||||||
const Action vote = Action("vote", true);
|
|
||||||
Role role1({vote, kill, heal});
|
|
||||||
Role role2({heal});
|
|
||||||
Event event1 = Event("Event 1", 1710087355, 1, true, {}, {});
|
|
||||||
Event event2 = Event("Event 2", 1710087363, 1, true, {kill}, {});
|
|
||||||
Event event3 = Event("Event 3", 1710087369, 1, true, {}, {kill});
|
|
||||||
std::vector<Event> relatedEvents({event2, event3});
|
|
||||||
Player player1 = Player(69, "player1", role1, PlayerStatus::ALIVE);
|
|
||||||
Player player2 = Player(420, "player2", role1, PlayerStatus::ALIVE);
|
|
||||||
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS, {player1, player2});
|
|
||||||
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED, {});
|
|
||||||
int actionValidated = validateAction(&player1, &kill, &room1, &relatedEvents, &player2);
|
|
||||||
printf("The action validation result is %u\n", actionValidated);
|
|
||||||
}
|
|
||||||
|
|
||||||
int validateAction(
|
int validateAction(
|
||||||
Player *actor, const Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr) {
|
Player *actor, const Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr) {
|
||||||
if (!actor) {
|
if (!actor) {
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
#include "prep/prep.hh"
|
#include "prep/prep.hh"
|
||||||
|
|
||||||
void run();
|
|
||||||
|
|
||||||
bool playerBelongsToRoom(Player *player, Room *room);
|
bool playerBelongsToRoom(Player *player, Room *room);
|
||||||
bool actionBelongsToRole(Role *role, const Action *action);
|
bool actionBelongsToRole(Role *role, const Action *action);
|
||||||
bool isActionAllowed(const Action *action, std::vector<Event> *relevantEvents);
|
bool isActionAllowed(const Action *action, std::vector<Event> *relevantEvents);
|
||||||
|
|||||||
16
src/main.cpp
16
src/main.cpp
@ -3,6 +3,20 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
run();
|
const Action kill = Action("kill", true);
|
||||||
|
const Action heal = Action("heal", true);
|
||||||
|
const Action vote = Action("vote", true);
|
||||||
|
Role role1({vote, kill, heal});
|
||||||
|
Role role2({heal});
|
||||||
|
Event event1 = Event("Event 1", 1710087355, 1, true, {}, {});
|
||||||
|
Event event2 = Event("Event 2", 1710087363, 1, true, {kill}, {});
|
||||||
|
Event event3 = Event("Event 3", 1710087369, 1, true, {}, {kill});
|
||||||
|
std::vector<Event> relatedEvents({event2, event3});
|
||||||
|
Player player1 = Player(69, "player1", role1, PlayerStatus::ALIVE);
|
||||||
|
Player player2 = Player(420, "player2", role1, PlayerStatus::ALIVE);
|
||||||
|
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS, {player1, player2});
|
||||||
|
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED, {});
|
||||||
|
int actionValidated = validateAction(&player1, &kill, &room1, &relatedEvents, &player2);
|
||||||
|
printf("The action validation result is %u\n", actionValidated);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user