-
Notifications
You must be signed in to change notification settings - Fork 0
/
chess_player.h
63 lines (50 loc) · 1.84 KB
/
chess_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
#ifndef _CHESS_PLAYER_H_
#define _CHESS_PLAYER_H_
#include <random>
#include <vector>
#include "chess_board.h"
using std::vector;
class Player {
public:
const Team team;
Player(Team team) : team(team) {}
virtual Move get_move(const Board& board, const vector<Move>& moves) const = 0;
virtual const char* name() const;
};
class RandomPlayer : public Player {
mutable std::default_random_engine random_number_generator;
public:
RandomPlayer(Team team);
Move get_move(const Board& board, const vector<Move>& moves) const override;
};
class HumanPlayer : public Player {
public:
HumanPlayer(Team team);
Move get_move(const Board& board, const vector<Move>& moves) const override;
};
class AIPlayer : public Player {
mutable std::default_random_engine random_number_generator;
bool good_move(const Move move, const Board& board) const;
bool is_more_value(const ChessPiece& p1, const ChessPiece& p2) const;
int minimax(const Board& b, Move move, int depth, int alpha, int beta, bool white) const;
int value(const ChessPiece& p) const;
public:
AIPlayer(Team team);
int eval(const Board& b) const;
Move get_move(const Board& board, const vector<Move>& moves) const override;
};
// CapturePlayer plays a random move that captures an opponents piece.
// If there is no such move, then it plays a random move.
class CapturePlayer : public Player {
mutable std::default_random_engine random_number_generator;
public:
CapturePlayer(Team team);
Move get_move(const Board& board, const vector<Move>& moves) const override;
};
class CheckMateCapturePlayer : public Player {
mutable std::default_random_engine random_number_generator;
public:
CheckMateCapturePlayer(Team team);
Move get_move(const Board& board, const vector<Move>& moves) const override;
};
#endif // _CHESS_PLAYER_H_#pragma once