-
Notifications
You must be signed in to change notification settings - Fork 0
/
King.cpp
22 lines (20 loc) · 712 Bytes
/
King.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Joshua Hahn jhahn19
// Kevin Kim kkim170
// Elissa Matlock ematloc1
//TODO: make sure includes are correct
#include "King.h"
namespace Chess {
bool King::legal_move_shape(std::pair<char, char> start, std::pair<char, char> end) const {
//check if no move (the user wants to move to the same square)
if (start == end) return false;
int horizontal_distance = end.first - start.first;
int vertical_distance = end.second - start.second;
//absolute value
if (vertical_distance < 0) vertical_distance *= -1;
if (horizontal_distance < 0) horizontal_distance *= -1;
if (vertical_distance <= 1 && horizontal_distance <= 1) {
return true;
} //else
return false;
}
}