Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 15 / Chess / Figures / Pawn / Pawn.cpp
diff options
context:
space:
mode:
Commitd489848bab395aea447bf6fe462f7c4f603dee1a (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2021-06-12 17:01:20 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2021-06-12 17:01:20 +0300
Files1bf68497f483098888dc1f94eadbf1d50894569a /Sem. 15/Chess/Figures/Pawn/Pawn.cpp
Object-oriented_programming_FMI-d489848bab395aea447bf6fe462f7c4f603dee1a.tar
Object-oriented_programming_FMI-d489848bab395aea447bf6fe462f7c4f603dee1a.tar.gz
Object-oriented_programming_FMI-d489848bab395aea447bf6fe462f7c4f603dee1a.zip
Parentd060147c32ecebaecb31cf5a93aae75318dc7ca6 (diff)
sem 16
1 files changed, 7 insertions, 18 deletions
-rw-r--r--Sem. 15/Chess/Figures/Pawn/Pawn.cpp25
diff --git a/Sem. 15/Chess/Figures/Pawn/Pawn.cpp b/Sem. 15/Chess/Figures/Pawn/Pawn.cpp
index fd04dad..347032b 100644
--- a/Sem. 15/Chess/Figures/Pawn/Pawn.cpp
+++ b/Sem. 15/Chess/Figures/Pawn/Pawn.cpp
@@ -1,27 +1,16 @@
#include "Pawn.h"
#include <cmath>
-Pawn::Pawn(bool isWhite) : Figure(isWhite), isFirstMove(true)
+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 (currentX != destX)
- return false;
-
- int diff = destY - currentY;
-
- if (abs(diff) > 2)
- return false;
-
- if (diff < 0 && getIsWhite() || diff > 0 && !getIsWhite())
- return false;
-
- if (!abs(diff) == 2 || isFirstMove)
- {
- return true;
- }
- return false;*/
- return false;
+ 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())