-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtGame.cpp
More file actions
117 lines (106 loc) · 2.54 KB
/
tGame.cpp
File metadata and controls
117 lines (106 loc) · 2.54 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
/*
* tGame.cpp
* HMMBrain
*
* Created by Arend on 9/23/10.
* Copyright 2010 __MyCompanyName__. All rights reserved.
*
*/
#include "tGame.h"
#include "math.h"
tGame::tGame(){
int i,x,y,j;
}
tGame::~tGame(){
}
void tGame::executeAgentStepInMaze(tAgent* agent,int mazeToUse){
int c,action,i;
double angle;
double d=sqrt((agent->xPos*agent->xPos)+(agent->yPos*agent->yPos));
/*
if(agent->xPos>0)
agent->states[0]=0;
else
agent->states[0]=1;
if(agent->yPos>0)
agent->states[1]=0;
else
agent->states[1]=1;
agent->updateStates();
action=(agent->states[maxNodes-1]&1)+((agent->states[maxNodes-2]&1)<<1);
switch(action){
case 0:
agent->xPos+=1.0;
agent->yPos+=1.0;
break;
case 1:
agent->xPos+=1.0;
agent->yPos-=1.0;
break;
case 2:
agent->xPos-=1.0;
agent->yPos+=1.0;
break;
case 3:
agent->xPos-=1.0;
agent->yPos-=1.0;
break;
}
*/
angle=atan2(-1.0*agent->yPos,-1.0*agent->xPos)*180.0/cPI;
agent->states[maxNodes-1]=0;
agent->states[maxNodes-2]=0;
agent->states[maxNodes-3]=0;
angle=agent->direction-angle;
for(i=0;i<5;i++)
agent->states[i]=0;
if(abs((int)angle)<90){
agent->states[2+(int)(angle/36.0)]=1;
}
// printf("%f %f %i ",angle,agent->direction,4+(int)(angle/10.0));
// for(i=0;i<9;i++)
// printf("%i",agent->states[i]);
// printf("\n");
// c=0;
// do{
// c++;
agent->updateStates();
action=(agent->states[maxNodes-1]&1)+((agent->states[maxNodes-2]&1)<<1)+((agent->states[maxNodes-3]&1)<<1);
// }while ((c<3)&&(action==0));
switch(action){
case 0:
case 4:break;
case 1:
agent->direction-=5.0;
while(agent->direction>360.0) agent->direction-=360.0;
while(agent->direction<0.0) agent->direction+=360.0;
break;
case 2:
agent->direction+=5.0;
while(agent->direction>360.0) agent->direction-=360.0;
while(agent->direction<0.0) agent->direction+=360.0;
break;
case 3:
agent->xPos+=cos(agent->direction*(cPI/180.0));
agent->yPos+=sin(agent->direction*(cPI/180.0));
break;
case 5:
agent->direction-=15.0;
while(agent->direction>360.0) agent->direction-=360.0;
while(agent->direction<0.0) agent->direction+=360.0;
break;
case 6:
agent->direction+=15.0;
while(agent->direction>360.0) agent->direction-=360.0;
while(agent->direction<0.0) agent->direction+=360.0;
break;
case 7:
agent->xPos+=cos(agent->direction*(cPI/180.0))*2.0;
agent->yPos+=sin(agent->direction*(cPI/180.0))*2.0;
break;
}
double nd=sqrt((agent->xPos*agent->xPos)+(agent->yPos*agent->yPos));
if(nd<1.0)
nd=1.0;
agent->fitness+=1.0/(nd*nd*nd);
}