refactor: move run function to main

This commit is contained in:
Kristofers Solo 2024-03-14 00:27:18 +02:00
parent 8e06b54380
commit 03933af4b2
3 changed files with 15 additions and 21 deletions

View File

@ -20,24 +20,6 @@ enum VALIDATION_STATUS {
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(
Player *actor, const Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr) {
if (!actor) {

View File

@ -1,7 +1,5 @@
#include "prep/prep.hh"
void run();
bool playerBelongsToRoom(Player *player, Room *room);
bool actionBelongsToRole(Role *role, const Action *action);
bool isActionAllowed(const Action *action, std::vector<Event> *relevantEvents);

View File

@ -3,6 +3,20 @@
#include <stdlib.h>
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;
}