-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartGhost.cpp
More file actions
47 lines (35 loc) · 942 Bytes
/
SmartGhost.cpp
File metadata and controls
47 lines (35 loc) · 942 Bytes
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
#include "SmartGhost.h"
void SmartGhost::moveCreature(Board& board, std::ofstream& stepsFile)
{
printBeforeGhost(board);
checkObstacle(board, getDirection(board));
moveGhost(board);
if (statusCreature == SAVE)
updateStepsFile(stepsFile, "Ghost", key);
}
//check the minimal distance from every valid (not wall) direction
void SmartGhost::checkBestDirection(Board& board,int pacmanCurY,int pacmanCurX)
{
int dir,dist,min=5555;
int prevGhostX, prevGhostY;
prevGhostX = coord.getX();
prevGhostY = coord.getY();
for (int i = 0; i < 4; i++)
{
key = i;
coord.setX(prevGhostX);
coord.setY(prevGhostY);
if (!checkObstacle(board, getDirection(board)))
{
dist = item.minDistance(board, coord.getY(), coord.getX(), pacmanCurY, pacmanCurX);
if (dist < min)
{
min = dist;
dir = i;
}
}
}
coord.setX(prevGhostX);
coord.setY(prevGhostY);
key = dir;
}