-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.h
109 lines (83 loc) · 2.63 KB
/
player.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// provides player classes
#ifndef PLAYER_H
#define PLAYER_H
#include "util.h"
#include "pieces.h"
using namespace std;
// Forward declaration
class Board;
// ! NULL_PLR added to return from stringToPlayerType in main.cc
enum class PlayerType
{
Human,
Computer,
NULL_PLR,
};
class Player
{
Colour team;
PlayerType p;
// Computer overwrites to call generateMove, Human overwrites to call getHumanMove()
virtual Move doGetNextMove(vector<Move>& validMoves, Board *b) const = 0;
public:
Player(const Colour team, const PlayerType p);
virtual ~Player() = default;
// NVI - calls doGetNextMove()
Move getNextMove(vector<Move>& validMoves, Board *b) const;
Colour getColour() const;
PlayerType getPlayerType() const;
};
class Human final : public Player
{
// get next move from input and return it as a Move object
// this will throw if it fails to read from cin - handled in main
Move getHumanMove(vector<Move>& validMoves, Board *b) const;
public:
Human(const Colour team, const PlayerType p);
// call getHumanMove()
Move doGetNextMove(vector<Move>& validMoves, Board *b) const override;
};
class Computer : public Player
{
protected:
int lvl;
// generate a Move object using algorithm depending on Computer level
// pass it generateValidMoves() rvalue
virtual Move generateMove(vector<Move> &moves, Board *b) const = 0;
public:
Computer(const Colour team, const PlayerType p, const int lvl);
int getLvl() const;
// NVI - call generateMove()
Move doGetNextMove(vector<Move>& validMoves, Board *b) const override;
};
class LevelOne final : public Computer
{
Move generateMove(vector<Move>& moves, Board *b) const override; // random pick
public:
LevelOne(const Colour team, const PlayerType p, const int lvl);
~LevelOne();
};
class LevelTwo final : public Computer
{
Move generateMove(vector<Move>& moves, Board *b) const override; // prefers capture & checks
public:
LevelTwo(const Colour team, const PlayerType p, const int lvl);
~LevelTwo();
};
class LevelThree final : public Computer
{
Move generateMove(vector<Move>& moves, Board *b) const override; // prefers avoiding capture, capture & checks
public:
LevelThree(const Colour team, const PlayerType p, const int lvl);
~LevelThree();
};
class LevelFour final : public Computer
{
Move generateMove(vector<Move>& moves, Board *b) const override; // something sophisticated
public:
LevelFour(const Colour team, const PlayerType p, const int lvl);
~LevelFour();
};
bool isHuman(const Player* p);
bool isWhiteTeam(const Player* p);
#endif