-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoodGhost.cpp
More file actions
69 lines (55 loc) · 1.28 KB
/
GoodGhost.cpp
File metadata and controls
69 lines (55 loc) · 1.28 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
#include "GoodGhost.h"
void GoodGhost::moveCreature(Board& board, std::ofstream& stepsFile) {
// ghost is in his smart moves
if (countSmartMoves == 0 && !isStupid)
{
countSmartMoves = rand() % LOWER_RANGE + ADD_TO_RANGE; //randomly chosing ~20(15-25) smart moves
smartMoves = countSmartMoves;
}
// ghost move 5 "stupid" steps
if (isStupid)
{
getStupid();
printBeforeGhost(board);
moveGhost(board);
countStupidMoves++;
if (countStupidMoves == STUPID_MOVES)
{
countStupidMoves = 0;
isStupid = false;
}
if (statusCreature == SAVE)
updateStepsFile(stepsFile, "Ghost", key);
}
else
{
SmartGhost::moveCreature(board,stepsFile);
countSmartMoves--;
if (countSmartMoves == 0)
isStupid = true;
}
}
void GoodGhost::initAferDeathGhost()
{
setCounter(0);
countSmartMoves = countStupidMoves = countMoves = 0;
isStupid = is5Moves = false;
}
//get to each 5 moves same direction
void GoodGhost::getStupid()
{
if (getCounter() % smartMoves == 0)
{
is5Moves = true;
do {
prevDir = curDir;
curDir = rand() % 4; //every number symbolize a direction
} while (curDir == prevDir);
}
if (getCounter() % smartMoves < STUPID_MOVES)
{
key = curDir;
}
else
is5Moves = false;
}