-
Notifications
You must be signed in to change notification settings - Fork 0
/
humanPlayer.cpp
57 lines (52 loc) · 1.14 KB
/
humanPlayer.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
#include "humanPlayer.h"
HumanPlayer::HumanPlayer(const char *name, char symbol, Color c) : Player(name, symbol, c) {}
HumanPlayer::~HumanPlayer() {}
bool HumanPlayer::validMove(Board &board, Position &pos, char goal)
{
//check if the move is valid
if (board.isPath(pos) || board.posIsChar(pos, goal))
{
//change the player position in the board
Position temp = getPos();
board.updateOldPosition(temp, pos,getSymbol());
setPos(pos);
return true;
}
else
{
return false;
}
}
//1 successfull move or 0 if the move was not successful
bool HumanPlayer::nextMove(Board &board, char symbol, Control c)
{
Position pos = getPos();
switch (c)
{
case UP:
pos.first--;
break;
case DOWN:
pos.first++;
break;
case LEFT:
pos.second--;
break;
case RIGHT:
pos.second++;
break;
case SPACE:
return 1;
default:
return 0;
}
//ελεγχος για επιτυχή κίνηση
if (validMove(board, pos, symbol))
{
return 1;
}
else
{
return 0;
}
}