Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 15 / Chess / Figures / Knight / Knight.cpp
blob: e6db119bcdc5b1778df0ecdb82f0be11fe7cd934 (plain) (blame)
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
#include "Knight.h"
#include <cmath>

Knight::Knight(bool isWhite) : Figure(isWhite)
{}
bool Knight::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const
{
	int xMovеment[] = { 1, 1, -1, -1, 2, -2, 2, -2 };
	int yMovеment[] = { 2, -2, 2, -2, 1, 1, -1, -1 };

	for (int i = 0; i < 8; i++)
	{
		if (currentX + xMovеment[i] == destX &&
			currentY + yMovеment[i] == destY)
			return true;
	}
	return false;
}

void Knight::print() const
{
	if (getIsWhite())
		std::cout << 'K';
	else
		std::cout << 'k';
}