forked from jake-edmonstone/Chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstractplayer.h
More file actions
77 lines (66 loc) · 3 KB
/
abstractplayer.h
File metadata and controls
77 lines (66 loc) · 3 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
70
71
72
73
74
75
76
77
#ifndef ABSTRACTPLAYER_H
#define ABSTRACTPLAYER_H
#include "chessboard.h"
struct State {
ChessBoard cb;
std::pair<std::string, std::string> move;
std::vector<std::shared_ptr<State>> nextStates;
};
class AbstractPlayer {
protected:
const ChessBoard *cb; // pointer to const ChessBoard. Each player can "observe" the board but not change it
std::string colour; // colour ("black" or "white")
public:
AbstractPlayer(ChessBoard *cb, std::string colour); // ctor
virtual ~AbstractPlayer() = 0; // virtual destructor
// this is the main functionality of the players, returns a pair of strings that describes the move.
// this is what allows for the polymorphism of players (computer vs human, computer vs computer etc.)
virtual std::pair<std::string, std::string>getMove(std::string config="sleep") const = 0;
std::string getColour() const; // getter
virtual char getPromotionDecision() const = 0; // for when a player can promote a pawn
// gets all moves that lead to check, but not checkmate for the player
std::vector<std::pair<std::string, std::string>> getMovesCheck() const;
// gets all moves that lead to checkmate for the player
std::vector<std::pair<std::string, std::string>> getMovesCheckMate() const;
// gets all moves that lead to a capture
std::vector<std::pair<std::string, std::string>> getMovesCapture() const;
// gets all moves that avoid a threat
std::vector<std::pair<std::string, std::string>> getMovesAvoidThreat() const;
// fetches a random move
std::pair<std::string, std::string> getRandomMove() const;
};
class Human: public AbstractPlayer {
public:
Human(ChessBoard *cb, std::string colour);
std::pair<std::string, std::string>getMove(std::string config="nosleep") const override;
char getPromotionDecision() const override;
};
class Computer1: public AbstractPlayer {
public:
Computer1(ChessBoard *cb, std::string colour);
std::pair<std::string, std::string>getMove(std::string config="sleep") const override;
char getPromotionDecision() const override;
};
class Computer2: public AbstractPlayer {
public:
Computer2(ChessBoard *cb, std::string colour);
std::pair<std::string, std::string>getMove(std::string config="sleep") const override;
char getPromotionDecision() const override;
};
class Computer3: public AbstractPlayer {
public:
Computer3(ChessBoard *cb, std::string colour);
std::pair<std::string, std::string>getMove(std::string config="sleep") const override;
char getPromotionDecision() const override;
};
class Computer4: public AbstractPlayer {
public:
Computer4(ChessBoard *cb, std::string colour);
std::pair<std::string, std::string>getMove(std::string config="sleep") const override;
void findPossibleMoves(State& state, int depth, bool turn) const;
std::pair<std::string, std::string> getOptimalMove(State& root, int peakValSoFar) const;
int getPeakValueDownPath(const State* state, std::string bound) const;
int minimax(const ChessBoard* bp, int depth, bool isblack) const;
char getPromotionDecision() const override;
};
#endif