Coverage report for ai


src/
File: src/actions/Action.cpp
Date: 2024-06-25 10:57:00
Lines:
4/15
26.7%
Functions:
2/5
40.0%
Branches:
1/12
8.3%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** zappy/ai
4 ** File description:
5 ** Actions.cpp
6 */
7
8 #include "Action.hpp"
9
10 // TODO: how to put it in constant without conflict ?
11 std::map<Action, ActionInfo> actionMap = {
12 {DEFAULT, ActionInfo("Default", 0)},
13 {FORWARD, ActionInfo("Forward", 7)},
14 {RIGHT, ActionInfo("Right", 7)},
15 {LEFT, ActionInfo("Left", 7)},
16 {LOOK, ActionInfo("Look", 7)},
17 {INVENTORY, ActionInfo("Inventory", 1)},
18 {BROADCAST, ActionInfo("Broadcast", 7)},
19 {CONNECT_NBR, ActionInfo("Connect_nbr", 0)},
20 {FORK, ActionInfo("Fork", 42)},
21 {EJECT, ActionInfo("Eject", 7)},
22 {TAKE, ActionInfo("Take", 7)},
23 {SET, ActionInfo("Set", 7)},
24 {INCANTATION, ActionInfo("Incantation", 300)},
25 };
26
27
1/2
✓ Branch 1 taken 364 times.
✗ Branch 2 not taken.
364 ActionInfo::ActionInfo(const std::string &name, unsigned int timeUnitCost) : _name(name), _timeUnitCost(timeUnitCost)
28 {
29 364 }
30
31 1092 ActionInfo::~ActionInfo()
32 {
33 1092 }
34
35 std::string ActionInfo::getName() const
36 {
37 return _name;
38 }
39
40 unsigned int ActionInfo::getTimeUnitCost() const
41 {
42 return _timeUnitCost;
43 }
44
45 ActionInfo getActionInfo(Action action)
46 {
47 auto it = actionMap.find(action);
48
49 if (it != actionMap.end())
50 {
51 ActionInfo actionInfo = it->second;
52
53 actionInfo.action = action;
54 return actionInfo;
55 }
56 else
57 throw ActionInfoException("Action not found in actionMap");
58 }
59