-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcelltype.cpp
61 lines (54 loc) · 1.2 KB
/
celltype.cpp
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
#include "celltype.h"
#include <math.h>
#include <qglobal.h>
//enum ActionEnum{up,down,right,left,forward,backward,null=0,death};
CellType::CellType()
{
bool actionSet[8];
for(int i = 0;i<8;i++)actionSet[i]=false;
for(int i = 0;i<8;i++){
int indexRnd=0;
do{
indexRnd=round(qrand()*8);
}while(actionSet[indexRnd] && i<8);
actionSet[indexRnd] = true;
_actions[i]=ActionEnum(indexRnd);
}
}
CellType::CellType(int indexActions[8])
{
for(int i =0;i<8;i++){
_actions[i] = ActionEnum(indexActions[i]);
}
}
QString CellType::getAction(int i){
switch(this->_actions[i]){
case(up):
return "up";
break;
case(down):
return "down";
break;
case(right):
return "right";
break;
case(left):
return "left";
break;
case(forward):
return "forward";
break;
case(backward):
return "backward";
break;
case(nothing):
return "nothing";
break;
case(death):
return "death";
break;
default:
return "";
break;
}
}