-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTarget.h
More file actions
116 lines (105 loc) · 2.7 KB
/
Target.h
File metadata and controls
116 lines (105 loc) · 2.7 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
#include <random>
#include <algorithm>
#include <vector>
using namespace std ;
enum Transition {LEFT, STAY, RIGHT} ;
class Cell
{
public:
Cell() {}
~Cell() {}
// Initialise domain with empty cells
void SetNumCells(int numCells){
occupied.clear() ;
for (int i = 0; i < numCells; i++)
occupied.push_back(false) ;
}
// Change the occupancy state of the cell
void ToggleOccupied(int state){
occupied[state] = !occupied[state] ;
}
vector<bool> occupied ;
} ;
class Target
{
public:
Target(int state, int eState): numActions(3), itsState(state), itsEnergy(eState) {}
~Target() {}
// Perform target state transition
void TargetTransition(Cell & AllCells){
int temp = rand() % numActions ;
// Only make transition if transition cell is not occupied
int newState ;
switch (temp){
case 0:
itsAction = LEFT ;
newState = max(0,itsState-1) ;
if (!AllCells.occupied[newState]){ // make transition
AllCells.ToggleOccupied(itsState) ;
itsState = newState ;
AllCells.ToggleOccupied(itsState) ;
}
break ;
case 1:
itsAction = STAY ;
break ;
case 2:
itsAction = RIGHT ;
newState = min(itsState+1,(int)AllCells.occupied.size()-1) ;
if (!AllCells.occupied[newState]){ // make transition
AllCells.ToggleOccupied(itsState) ;
itsState = newState ;
AllCells.ToggleOccupied(itsState) ;
}
break ;
}
}
void ReduceEnergy() {itsEnergy-- ;}
int GetState() {return itsState ;}
int GetEnergy() {return itsEnergy ;}
private:
int numActions ;
int itsState ;
int itsEnergy ;
vector<double> itsTransition ;
Transition itsAction ;
} ;
//void Target::TargetTransition(Cell & AllCells){
// default_random_engine generator;
// uniform_real_distribution<double> distribution(1,100);
// double pTrans = distribution(generator) / 100.0 ;
// int temp ;
// for (int i = 0; i < cdfActions; i++){
// if (pTrans <= itsTransition[i]){
// temp = i ;
// break ;
// }
// }
//
// // Only make transition if transition cell is not occupied
// int newState ;
// switch (temp){
// case 0:
// itsAction = LEFT ;
// newState = min(0,itsState-1) ;
// if (!AllCells.occupied[newState]){ // make transition
// AllCells.ToggleOccupied(itsState) ;
// itsState = newState ;
// AllCells.ToggleOccupied(itsState) ;
// }
// break ;
// case 1:
// itsAction = STAY ;
// break ;
// case 2:
// itsAction = RIGHT ;
// newState = max(itsState+1,(int)AllCells.occupied.size()) ;
// if (!AllCells.occupied[newState]){ // make transition
// AllCells.ToggleOccupied(itsState) ;
// itsState = newState ;
// AllCells.ToggleOccupied(itsState) ;
// }
// break ;
// }
//}