-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCEAController.cpp
More file actions
88 lines (77 loc) · 3.09 KB
/
Copy pathCEAController.cpp
File metadata and controls
88 lines (77 loc) · 3.09 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
/**
)
( /( ( )
)\()) ( ( ( ( ) )\ ( ( /((
((_)\ ))\ ))\ )( ( )\ /(( ( ((_)))\ )\())\ ( (
_((_)/((_)((_|()\ )\ ((_)(_))\ )\ _ /((_|_))((_) )\ )\ )
| \| (_))(_))( ((_)((_) | __|)((_|(_) (_))(| |_ (_)((_)_(_/(
| .` / -_) || | '_/ _ \ | _|\ V / _ \ | || | _|| / _ \ ' \))
|_|\_\___|\_,_|_| \___/ |___|\_/\___/_|\_,_|\__||_\___/_||_|
( ) ( (
)\ ( /(( )\ )\ ( (
(((_) ( ( )\())( ( ((_|(_)))\ )(
)\___ )\ )\ )(_))(()\ )\ _ _ /((_|()\
((/ __|((_)_(_/(| |_ ((_)((_) || (_)) ((_)
| (__/ _ \ ' \)) _| '_/ _ \ || / -_)| '_|
\___\___/_||_| \__|_| \___/_||_\___||_|
*/
#include "CEAController.h"
CEAController::CEAController(HWND hwndMain):
CContController(hwndMain)
{
}
void CEAController::InitializeLearningAlgorithm(void)
{
//TODO: set up any data structures you need to store the genomes here
}
/**
Returns the dot product between the sweeper's look vector and the vector from the sweeper to the object
*/
inline double dot_between_vlook_and_vObject(const CContMinesweeper &s,const CContCollisionObject &o){
SVector2D<double> vLook = s.getLookAt();
SVector2D<double> pt = o.getPosition();
//get the vector to the point from the sweepers current position:
SVector2D<double> vObj(SVector2D<double>(pt.x,pt.y) - s.Position());
Vec2DNormalize<double>(vObj);
//remember (MAM1000 / CSC3020) the dot product between two normalized vectors returns
//1 if the two vectors point in the same direction
//0 if the two vectors are perpendicular
//-1 if the two vectors are pointing in opposite directions
return Vec2DDot<double>(vLook,vObj);
}
bool CEAController::Update(void)
{
uint cDead = std::count_if(m_vecSweepers.begin(),
m_vecSweepers.end(),
[](CContMinesweeper * s)->bool{
return s->isDead();
});
if (cDead == CParams::iNumSweepers){
printf("All dead ... skipping to next iteration\n");
m_iTicks = CParams::iNumTicks;
}
if (m_iTicks+1 >= CParams::iNumTicks){
//TODO: when the round is over select, cross over and mutate here
}
CContController::Update(); //call the parent's class update. Do not delete this.
for (uint i = 0; i < CParams::iNumSweepers; ++i){
CContMinesweeper * s = m_vecSweepers[i];
//TODO: set up your sensory inputs and motor outputs here
/*
//This turns the sweeper towards a point
SPoint pt(m_vecObjects[(s)->getClosestMine()]->getPosition().x,
m_vecObjects[(s)->getClosestMine()]->getPosition().y);
(s)->turn(pt, 1);
//This turns the sweeper away from a point
SPoint pt(m_vecObjects[(s)->getClosestRock()]->getPosition().x,
m_vecObjects[(s)->getClosestRock()]->getPosition().y);
(s)->turn(pt,1,false);
break;
*/
}
return true; //method returns true if successful. Do not delete this.
}
CEAController::~CEAController(void)
{
//TODO:: release any allocations here
}