-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueen.cpp
42 lines (39 loc) · 1.3 KB
/
Queen.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
35
36
37
38
39
40
41
#include <iostream>
#include "Queen.h"
#include "Piece.h"
using std::pair;
// Checks to make sure that the move entered fits the piece
bool Queen::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) {
// Queen did not move at all
return false;
}
int m = abs(start.first - end.first);
int n = abs(start.second - end.second);
if(m == n) {
// Queen moves in a diagonal direction
return true;
}
else if(start.first == end.first && start.second != end.second) {
// Queen moves horizontally
return true;
}
else if(start.first != end.first && start.second == end.second) {
// Queen moves vertically
return true;
}
else {
// Queen does not move in a valid way
return false;
}
}