-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoordfix.cpp
404 lines (303 loc) · 7.52 KB
/
coordfix.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#include <math.h>
//#include <iostream>
#include "coordfix.h"
#include "geom.h"
CoordFix::CoordFix() {
}
CoordFix::CoordFix(double width, double height, bool isOnLeft) {
_w = width;
_h = height;
_isOnLeft = isOnLeft;
_invY = false;
}
void CoordFix::setInvY(bool invY) {
_invY = invY;
}
bool CoordFix::isInvY() const {
return _invY;
}
double CoordFix::invcX(double x) const {
return _w - x;
}
double CoordFix::invcY(double y) const {
return _h - y;
}
double CoordFix::invcAngle(double angle) const {
return NormAngle(angle + M_PI);
}
double CoordFix::invcDx(double dx) const {
return -dx;
}
double CoordFix::invcDy(double dy) const {
return -dy;
}
double CoordFix::invyAngle(double angle) const {
return -angle;
}
double CoordFix::invyDAngle(double dAngle) const {
return -dAngle;
}
double CoordFix::fixX(double x) const {
if (_isOnLeft) {
return x;
} else {
return invcX(x);
}
}
double CoordFix::fixY(double y) const {
if (_isOnLeft != _invY) {
return y;
} else {
return invcY(y);
}
}
double CoordFix::fixAngle(double angle) const {
if (!_isOnLeft) {
angle = invcAngle(angle);
}
if (_invY) {
angle = invyAngle(angle);
}
return angle;
}
double CoordFix::fixDx(double dx) const {
if (_isOnLeft) {
return dx;
} else {
return invcDx(dx);
}
}
double CoordFix::fixDy(double dy) const {
if (_isOnLeft != _invY) {
return dy;
} else {
return invcDy(dy);
}
}
double CoordFix::fixDAngle(double dAngle) const {
if (_invY) {
return -dAngle;
} else {
return dAngle;
}
}
//
MoveF::MoveF() {
_move = 0;
}
MoveF::MoveF(Move* m, const CoordFix* fix) : _fix(fix) {
_move = m;
}
double MoveF::getSpeedUp() const {
return _move->getSpeedUp();
}
void MoveF::setSpeedUp(const double speedUp) {
_move->setSpeedUp(speedUp);
}
double MoveF::getTurn() const {
return _fix->fixDAngle(_move->getTurn());
}
void MoveF::setTurn(const double turn) {
return _move->setTurn(_fix->fixDAngle(turn));
}
ActionType MoveF::getAction() const {
return _move->getAction();
}
void MoveF::setAction(const ActionType action) {
_move->setAction(action);
}
double MoveF::getPassPower() const {
return _move->getPassPower();
}
void MoveF::setPassPower(const double passPower) {
_move->setPassPower(passPower);
}
double MoveF::getPassAngle() const {
return _fix->fixDAngle(_move->getPassAngle());
}
void MoveF::setPassAngle(const double passAngle) {
_move->setPassAngle(_fix->fixDAngle(passAngle));
}
int MoveF::getTeammateIndex() const {
return _move->getTeammateIndex();
}
void MoveF::setTeammateIndex(const int teammateIndex) {
_move->setTeammateIndex(teammateIndex);
}
//
GameF::GameF() {
}
GameF::GameF(const Game& g) : Game(g) {
}
double GameF::getWorldWidth() const {
return getRinkLeft() + getRinkRight();
}
double GameF::getWorldHeight() const {
return getRinkTop() + getRinkBottom();
}
//
PlayerF::PlayerF(const Player& p, const CoordFix* fix) : Player(p), _fix(fix) {
}
double PlayerF::getNetLeft() const {
return min(getNetFront(), getNetBack());
}
double PlayerF::getNetRight() const {
return max(getNetFront(), getNetBack());
}
double PlayerF::getNetFront() const {
return _fix->fixX(Player::getNetFront());
}
double PlayerF::getNetBack() const {
return _fix->fixX(Player::getNetBack());
}
//
UnitF::UnitF(const Unit& u, const CoordFix* fix) : Unit(u), _fix(fix) {
}
double UnitF::getX() const {
return _fix->fixX(Unit::getX());
}
double UnitF::getY() const {
return _fix->fixY(Unit::getY());
}
double UnitF::getSpeedX() const {
return _fix->fixDx(Unit::getSpeedX());
}
double UnitF::getSpeedY() const {
return _fix->fixDy(Unit::getSpeedY());
}
double UnitF::getAngle() const {
return _fix->fixAngle(Unit::getAngle());
}
double UnitF::getAngleTo(double x, double y) const {
return _fix->fixDAngle( Unit::getAngleTo(_fix->fixX(x), _fix->fixY(y)) );
}
double UnitF::getAngleTo(const UnitF& unit) const {
return _fix->fixDAngle( Unit::getAngleTo(unit) );
}
double UnitF::getDistanceTo(double x, double y) const {
return Unit::getDistanceTo(_fix->fixX(x), _fix->fixY(y));
}
double UnitF::getDistanceTo(const UnitF& unit) const {
return Unit::getDistanceTo(unit);
}
//
HockeyistF::HockeyistF() : UnitF(Hockeyist(), 0) {
}
HockeyistF::HockeyistF(const Hockeyist& h, const CoordFix* fix) : Hockeyist(h), UnitF(h, fix), _fix(fix) {
}
long long HockeyistF::getId() const {
return UnitF::getId();
}
double HockeyistF::getMass() const {
return UnitF::getMass();
}
double HockeyistF::getRadius() const {
return UnitF::getRadius();
}
double HockeyistF::getX() const {
return UnitF::getX();
}
double HockeyistF::getY() const {
return UnitF::getY();
}
double HockeyistF::getSpeedX() const {
return UnitF::getSpeedX();
}
double HockeyistF::getSpeedY() const {
return UnitF::getSpeedY();
}
double HockeyistF::getAngle() const {
return UnitF::getAngle();
}
double HockeyistF::getAngularSpeed() const {
return UnitF::getAngularSpeed();
}
double HockeyistF::getAngleTo(double x, double y) const {
return UnitF::getAngleTo(x, y);
}
double HockeyistF::getAngleTo(const UnitF& unit) const {
return UnitF::getAngleTo(unit);
}
double HockeyistF::getDistanceTo(double x, double y) const {
return UnitF::getDistanceTo(x, y);
}
double HockeyistF::getDistanceTo(const UnitF& unit) const {
return UnitF::getDistanceTo(unit);
}
//
PuckF::PuckF(const Puck& p, const CoordFix* fix) : Puck(p), UnitF(p, fix) {
}
long long PuckF::getId() const {
return UnitF::getId();
}
double PuckF::getMass() const {
return UnitF::getMass();
}
double PuckF::getRadius() const {
return UnitF::getRadius();
}
double PuckF::getX() const {
return UnitF::getX();
}
double PuckF::getY() const {
return UnitF::getY();
}
double PuckF::getSpeedX() const {
return UnitF::getSpeedX();
}
double PuckF::getSpeedY() const {
return UnitF::getSpeedY();
}
double PuckF::getAngle() const {
return UnitF::getAngle();
}
double PuckF::getAngularSpeed() const {
return UnitF::getAngularSpeed();
}
double PuckF::getAngleTo(double x, double y) const {
return UnitF::getAngleTo(x, y);
}
double PuckF::getAngleTo(const UnitF& unit) const {
return UnitF::getAngleTo(unit);
}
double PuckF::getDistanceTo(double x, double y) const {
return UnitF::getDistanceTo(x, y);
}
double PuckF::getDistanceTo(const UnitF& unit) const {
return UnitF::getDistanceTo(unit);
}
//
WorldF::WorldF() {
}
WorldF::WorldF(const World &w, const CoordFix* fix, const GameF& game) : World(w), _fix(fix) {
_game = game;
}
vector<PlayerF> WorldF::getPlayers() const {
vector<PlayerF> res;
res.push_back(getMyPlayer());
res.push_back(getOpponentPlayer());
return res;
}
PlayerF WorldF::getMyPlayer() const {
return PlayerF(World::getMyPlayer(), _fix);
}
PlayerF WorldF::getOpponentPlayer() const {
return PlayerF(World::getOpponentPlayer(), _fix);
}
vector<HockeyistF> WorldF::getHockeyists() const {
const vector<Hockeyist>& in = World::getHockeyists();
vector<HockeyistF> out;
for (vector<Hockeyist>::const_iterator it = in.cbegin(); it != in.cend(); ++it) {
out.push_back(HockeyistF(*it, _fix));
}
return out;
}
PuckF WorldF::getPuck() const {
return PuckF(World::getPuck(), _fix);
}
double WorldF::getWidth() const {
return _game.getWorldWidth();
}
double WorldF::getHeight() const {
return _game.getWorldHeight();
}