-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bishop.cpp
36 lines (33 loc) · 972 Bytes
/
Bishop.cpp
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
#include <iostream>
#include "Bishop.h"
#include "Piece.h"
using std::pair;
using std::cout;
using std::endl;
// Checks to make sure that the move entered fits the piece
bool Bishop::legal_move_shape( pair< char , char > start , pair< char , char > end ) const {
if(start.first < 'A' || start.first > 'H' ||
end.first < 'A' || end.first > 'H') {
// Not a legal move. Too far horizontal off board
return false;
}
if(start.second < '1' || start.second > '8' ||
end.second < '1' || end.second > '8') {
// Not a legal move. Too far vertical off board
return false;
}
if(start.first == end.first && start.second == end.second) {
// Bishop did not move at all
return false;
}
int m = abs(start.first - end.first);
int n = abs(start.second - end.second);
if(m == n) {
// Bishop moves in a diagonal direction
return true;
}
else {
// Bishop does not move in a diagnoal direction
return false;
}
}