-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCarController.h
More file actions
135 lines (93 loc) · 2.91 KB
/
CCarController.h
File metadata and controls
135 lines (93 loc) · 2.91 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef CCARCONTROLLER_H
#define CCARCONTROLLER_H
//------------------------------------------------------------------------
//
// Name: CCarController.h
//
// Author: Morten Schnack 2013 (mosch@itu.dk)
//
// Desc: Controller class for NEAT Cars
//
//------------------------------------------------------------------------
#include <vector>
#include <sstream>
#include <string>
#include <windows.h>
#include "CCar.h"
#include "CParams.h"
#include "Cga.h"
using namespace std;
class CCarController
{
private:
//storage for the entire population of chromosomes
Cga* m_pPop;
//array of cars
vector<CCar> m_vecCars;
//array of best cars from last generation (used for
//display purposes when 'B' is pressed by the user)
vector<CCar> m_vecBestCars;
int m_NumCars;
//vertex buffer for objects
vector<SPoint> m_ObjectsVB;
//stores the average fitness per generation
vector<double> m_vecAvFitness;
//stores the best fitness per generation
vector<double> m_vecBestFitness;
//best fitness ever
double m_dBestFitness;
//pens we use for the stats
HPEN m_RedPen;
HPEN m_BluePen;
HPEN m_GreenPen;
HPEN m_GreyPenDotted;
HPEN m_RedPenDotted;
HPEN m_OldPen;
HBRUSH m_RedBrush;
HBRUSH m_BlueBrush;
//local copy of the handle to the application window
HWND m_hwndMain;
//local copy of the handle to the info window
HWND m_hwndInfo;
//toggles the speed at which the simulation runs
bool m_bFastRender;
//when set, renders the best performers from the
//previous generaion.
bool m_bRenderBest;
//cycles per generation
int m_iTicks;
//generation counter
int m_iGenerations;
//local copy of the client window dimensions
int m_cxClient, m_cyClient;
//this is the car who's memory cells are displayed
int m_iViewThisCar;
void PlotStats(HDC surface)const;
void RenderCars(HDC &surface, vector<CCar> &cars);
void RenderSensors (HDC &surface, vector<CCar> &cars);
public:
CCarController(HWND hwndMain, int cxClient, int cyClient);
~CCarController();
void Render(HDC &surface);
//renders the phenotypes of the four best performers from
//the previous generation
void RenderNetworks(HDC &surface);
bool Update();
//-------------------------------------accessor methods
bool FastRender()const{return m_bFastRender;}
void FastRender(bool arg){m_bFastRender = arg;}
void FastRenderToggle(){m_bFastRender = !m_bFastRender;}
bool RenderBest()const{return m_bRenderBest;}
void RenderBestToggle(){m_bRenderBest = !m_bRenderBest;}
void PassInfoHandle(HWND hnd){m_hwndInfo = hnd;}
vector<double> GetFitnessScores()const;
void ViewBest(int val)
{
if ( (val>4) || (val< 1) )
{
return;
}
m_iViewThisCar = val-1;
}
};
#endif