-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomStrategy.cpp
38 lines (30 loc) · 1.05 KB
/
RandomStrategy.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
#include "RandomStrategy.h"
//-----------------------------------------------------------------------------------------------//
void RandomStrategy::strategyMove(const Board& board, vector<Ghost>& ghosts, const Point& p_packman)
{
unsigned int i = 0;
Point nextStep;
while (i < ghosts.size())
{
if (countSteps == amountSameDir * ghosts.size()) // change direciton after amountSameDir steps
{
countSteps = 0;
}
if (countSteps >= 0 && countSteps < ghosts.size())
{
ghosts[i].setDirection(rand() % 4);
}
nextStep = ghosts[i].getCurr() + ghosts[i].getDirection();
if (board.isValidMove(nextStep))
{
ghosts[i].move(nextStep); // move creature
countSteps++;
i++;
}
else
{
ghosts[i].setDirection(rand() % 4);
}
}
}
//-----------------------------------------------------------------------------------------------//