-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.hpp
More file actions
93 lines (70 loc) · 2.15 KB
/
Player.hpp
File metadata and controls
93 lines (70 loc) · 2.15 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef PLAYER_HPP
#define PLAYER_HPP
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <string>
#include <iostream>
#include <vector>
#include "Utils.hpp"
#include "Move.hpp"
#include "BitOps.hpp"
#include "Board.hpp"
#include "MoveGenerator.hpp"
using namespace std;
class Player {
public:
Player(string in_name, bool in_is_human, bool white_in, bool on_top) : name(in_name), is_human(in_is_human), is_white(white_in) {
moveGenerator = new MoveGenerator(white_in, on_top);
}
//Actually makes the move;
Move* performMove(Board& board){
vector<Move*> moves = moveGenerator->generateMoves(board);
if (is_human){
if (next_move->to.row == next_move->from.row && next_move->to.col == next_move->from.col){
return nullptr;
}
//Find out if move is in legal moves set
for (auto& move : moves){
// cout << "Move!:" << endl;
// cout << move->to_string() << endl;
if (move->from == next_move->from && move->to == next_move->to){
return next_move;
}
}
//Not in the set.
return nullptr;
}else{
if (moves.empty()){
return nullptr;
}else{
return moves[rand() % moves.size()];
}
}
}
void setMoveFrom(Position& p){
if (!is_first_move){
delete next_move;
}
next_move = new Move();
next_move->from = p;
is_first_move = false;
}
void setMoveTo(Position& p){
next_move->to = p;
}
//Getters
bool isHuman(){
return is_human;
}
string getName(){
return name;
}
private:
Move* next_move;
MoveGenerator* moveGenerator;
string name;
bool is_human;
bool is_white;
bool is_first_move = true;
};
#endif