Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 15 / Chess / Figures / Pawn / Pawn.cpp
blob: 347032b81aa643d9208deb00b1a56e54324d4044 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "Pawn.h"
#include <cmath>
Pawn::Pawn(bool isWhite) : Figure(isWhite, PawnFigure), isFirstMove(true)
{}

bool Pawn::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const
{
	if (getIsWhite())
		return currentY - 1 == destY && abs((int)currentX - (int)destX) <= 1;
	else
		return currentY + 1 == destY && abs((int)currentX - (int)destX) <= 1;
}

void Pawn::print() const
{
	if (getIsWhite())
		std::cout << 'P';
	else
		std::cout << 'p';
}