Repository navigation
Expand file tree
/
Copy pathAction.cpp
More file actions
92 lines (72 loc) · 2.02 KB
/
Copy pathAction.cpp
File metadata and controls
92 lines (72 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "Action.h"
Action::Action()
{
actionFunction = NULL;
canActFunction = NULL;
rewardFunction = NULL;
return;
}
Action::~Action()
{
return;
}
// set*Function allows a callback function for the act, canAct and Reward
// functions for this Action to be set.
void Action::setActionFunction (bool (*function) (state&))
{
actionFunction = function;
return;
}
void Action::setCanActFunction (bool (*function) (state&))
{
canActFunction = function;
return;
}
void Action::setRewardFunction (int (*function) (state&))
{
rewardFunction = function;
return;
}
// act modifies the currentState based on the function provided by the user.
bool Action::act (state ¤tState)
{
return actionFunction(currentState);
}
// canAct determines if this action can be performed on the current state.
bool Action::canAct (state ¤tState)
{
return canActFunction(currentState);
}
// reward determines the amount to reward or punish the Agent for this action.
int Action::reward (state ¤tState)
{
return rewardFunction(currentState);
}
// set / get Description provides a description of the action. This is used
// when generating the policy report.
void Action::setDescription(string description)
{
this->description = description;
return;
}
string Action::getDescription()
{
return description;
}
// Action factory implementation.
//
// This function takes as parameters the description of the action, and the
// functions for the action (can act, reward and act). It returns a pointer
// to an Action object, which can be added to the Agent.
Action* createAction(bool (*actionFunc) (state&),
bool (*canActFunc) (state&),
int (*rewardFunc) (state&),
string description)
{
Action* action = new Action();
action->setDescription(description);
action->setActionFunction(actionFunc);
action->setCanActFunction(canActFunc);
action->setRewardFunction(rewardFunc);
return action;
}