-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbishop.cpp
More file actions
88 lines (71 loc) · 1.92 KB
/
Copy pathbishop.cpp
File metadata and controls
88 lines (71 loc) · 1.92 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
/*bishop.cpp - Written by Michael Wermert and Pengda Xie
* Description - This contains the function definitions for
* the bishop class in the piece.h file.
*/
#include "piece.h"
using namespace std;
//constructor
Bishop::Bishop(int row, int col, char color):Piece(row, col, color, 'B', 30)
{
}
void Bishop::ValidMoves(multimap<int, int> &moves, const vector<vector<Piece*> > &board)
{
moves.clear();
int r, c;
//check top left
for(r = this->row - 1, c = this->col - 1; r >= 0 && c >= 0;)
{
if(board[r][c] == nullptr)
moves.insert(make_pair(r, c));
else
{
if(board[r][c]->GetColor() != this->piece_color)
moves.insert(make_pair(r, c));
break;
}
--r;
--c;
}
//check top right
for(r = this->row - 1, c = this->col + 1; r >= 0 && c < (int)board.size();)
{
if(board[r][c] == nullptr)
moves.insert(make_pair(r, c));
else
{
if(board[r][c]->GetColor() != this->piece_color)
moves.insert(make_pair(r, c));
break;
}
--r;
++c;
}
//check bottom left
for(r = this->row + 1, c = this->col - 1; r < (int)board.size() && c >= 0;)
{
if(board[r][c] == nullptr)
moves.insert(make_pair(r, c));
else
{
if(board[r][c]->GetColor() != this->piece_color)
moves.insert(make_pair(r, c));
break;
}
++r;
--c;
}
//check bottom right
for(r = this->row + 1, c = this->col + 1; r < (int)board.size() && c < (int)board.size();)
{
if(board[r][c] == nullptr)
moves.insert(make_pair(r, c));
else
{
if(board[r][c]->GetColor() != this->piece_color)
moves.insert(make_pair(r, c));
break;
}
++r;
++c;
}
}