-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCController.h
More file actions
147 lines (111 loc) · 3.9 KB
/
Copy pathCController.h
File metadata and controls
147 lines (111 loc) · 3.9 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
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef CCONTROLLER_H
#define CCONTROLLER_H
//------------------------------------------------------------------------
//
// Name: CController.h
//
// Author: Mat Buckland 2002
//
// Desc: Controller class for the 'Smart Sweeper' example
//
//------------------------------------------------------------------------
#include <vector>
#include <sstream>
#include <string>
#include <fstream>
#include <windows.h>
#include "utils.h"
#include "C2DMatrix.h"
#include "SVector2D.h"
#include "CParams.h"
#include "CCollisionObject.h"
#include "CMinesweeper.h"
#include <algorithm>
//these hold the geometry of the sweepers and the mines
const int NumSweeperVerts = 16;
const SPoint sweeper[NumSweeperVerts] = {SPoint(-1, -1),
SPoint(-1, 1),
SPoint(-0.5, 1),
SPoint(-0.5, -1),
SPoint(0.5, -1),
SPoint(1, -1),
SPoint(1, 1),
SPoint(0.5, 1),
SPoint(-0.5, -0.5),
SPoint(0.5, -0.5),
SPoint(-0.5, 0.5),
SPoint(-0.25, 0.5),
SPoint(-0.25, 1.75),
SPoint(0.25, 1.75),
SPoint(0.25, 0.5),
SPoint(0.5, 0.5)};
const int NumMineVerts = 4;
const SPoint mine[NumMineVerts] = {SPoint(-1, -1),
SPoint(-1, 1),
SPoint(1, 1),
SPoint(1, -1)};
class CController
{
protected:
int m_NumSweepers;
int m_NumMines;
int m_NumSuperMines;
int m_NumRocks;
//vertex buffer for the sweeper shape's vertices
vector<SPoint> m_SweeperVB;
//vertex buffer for the mine shape's vertices
vector<SPoint> m_MineVB;
//stores the average MinesGathered per iteration for use
//in graphing.
vector<double> m_vecAvMinesGathered;
//stores the most MinesGathered per iteration
vector<double> m_vecMostMinesGathered;
//keep track of number of deaths per iteration
vector<double> m_vecDeaths;
//pens we use for the stats
HPEN m_RedPen;
HPEN m_BluePen;
HPEN m_GreenPen;
HPEN m_OldPen;
//handle to the application window
HWND m_hwndMain;
//toggles the speed at which the simulation runs
bool m_bFastRender;
//cycles per iteration
int m_iTicks;
//iteration counter
int m_iIterations;
//window dimensions
int cxClient, cyClient;
//this function plots a graph of the average and best MinesGathered
//over the course of a run
void PlotStats(HDC surface);
public:
CController(HWND hwndMain);
virtual ~CController();
template<typename pos_type>
void WorldTransform(vector<SPoint> &VBuffer, SVector2D<pos_type> vPos)
{
//create the world transformation matrix
C2DMatrix matTransform;
//scale
matTransform.Scale(CParams::dMineScale, CParams::dMineScale);
//translate
matTransform.Translate(vPos.x, vPos.y);
//transform the ships vertices
matTransform.TransformSPoints(VBuffer);
}
void Initialize();
virtual void Render(HDC surface) = 0;
virtual bool Update() = 0;
virtual void InitializeLearningAlgorithm(void) = 0;
virtual void InitializeSweepers(void) = 0;
virtual void InitializeMines(void) = 0;
virtual void InitializeSuperMines(void) = 0;
virtual void InitializeRocks(void) = 0;
//accessor methods
bool FastRender()const {return m_bFastRender;}
void FastRender(bool arg){m_bFastRender = arg;}
void FastRenderToggle() {m_bFastRender = !m_bFastRender;}
};
#endif