-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangry.cpp
56 lines (54 loc) · 1.52 KB
/
angry.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
#include "angry.h"
int Angry::decide(int yPacLoc, int xPacLoc, int pacDirection) {
if (yPacLoc <= yLoc && xPacLoc <= xLoc) { // tl
if (checkCollision(yLoc - 1, xLoc) || prevDecision == KEY_DOWN || !hunter)
if (checkCollision(yLoc, xLoc - 1) || prevDecision == KEY_RIGHT || !hunter)
if (rand() % 2)
return KEY_RIGHT;
else
return KEY_DOWN;
else
return KEY_LEFT;
else
return KEY_UP;
}
if (yPacLoc < yLoc && xPacLoc > xLoc) { // tr
if (checkCollision(yLoc - 1, xLoc) || prevDecision == KEY_DOWN || !hunter)
if (checkCollision(yLoc, xLoc + 1) || prevDecision == KEY_LEFT || !hunter)
if (rand() % 2)
return KEY_LEFT;
else
return KEY_DOWN;
else
return KEY_RIGHT;
else
return KEY_UP;
}
if (yPacLoc > yLoc && xPacLoc < xLoc) { // bl
if (checkCollision(yLoc + 1, xLoc) || prevDecision == KEY_UP || !hunter)
if (checkCollision(yLoc, xLoc - 1) || prevDecision == KEY_RIGHT || !hunter)
if (rand() % 2)
return KEY_RIGHT;
else
return KEY_UP;
else
return KEY_LEFT;
else
return KEY_DOWN;
}
if (yPacLoc >= yLoc && xPacLoc >= xLoc) { // br
if (checkCollision(yLoc + 1, xLoc) || prevDecision == KEY_UP || !hunter)
if (checkCollision(yLoc, xLoc + 1) || prevDecision == KEY_LEFT || !hunter)
if (rand() % 2)
return KEY_LEFT;
else
return KEY_UP;
else
return KEY_RIGHT;
else
return KEY_DOWN;
}
}
bool Angry::decideAndUpdate(int yPacLoc, int xPacLoc, int pacDirection) {
return update(decide(yPacLoc, xPacLoc, pacDirection));
}