-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.cpp
More file actions
85 lines (67 loc) · 1.8 KB
/
Copy pathplayer.cpp
File metadata and controls
85 lines (67 loc) · 1.8 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
#include "headers/player.h"
#include "headers/pieceslogic.h"
Pieces pieces;
Player::Player(){
unordered_map<int,int> pieces_value = pieces.pieces_value;
}
void Player::swap(int &a, int &b){
int temp = a;
a=b;
b=temp;
};
void Player::kill_piece(
int &start_piece,
int &end_piece,
vector<vector<int>> &board,
vector<int> &p1_collec,
vector<int> &p2_collec
){
if(start_piece>0 && end_piece<0){
//white p1 kills
p1_collec.push_back(end_piece);
end_piece=start_piece;
start_piece=0;
}else if(start_piece<0 && end_piece>0){
//black p2 kills
p2_collec.push_back(end_piece);
end_piece=start_piece;
start_piece=0;
}else{
cout<<"*****************"<<endl;
}
}
int Player::make_move(
vector<vector<int>> &board,
vector<vector<int>> &positions,
vector<int> &p1_collec,
vector<int> &p2_collec,
bool p1sturn
){
int x1=positions[0][0], x2=positions[1][0];
int y1=positions[0][1], y2=positions[1][1];
int start_piece = board[x1][y1];
int end_piece = board[x2][y2];
bool allowed = pieces.validate_move(start_piece, end_piece, board, positions,p1sturn);
if(allowed){
if(end_piece==0){
swap(board[x1][y1],board[x2][y2]);
return 1;
}
kill_piece(board[x1][y1],board[x2][y2],board,p1_collec,p2_collec);
return 1;
}
cout<<"~~~~~~~~~~~~~~~~~~~~~"<<endl;
}
int Player::score(vector<int> &collec){
int sum=0;
for(int piece:collec){
sum+=pieces_value[piece];
}
return sum;
}
void Player::print_collec(vector<int> &collec,unordered_map<int,char> map){
for(int piece:collec){
cout<<map[piece]<<" ";
}
cout<<endl;
}