aboutsummaryrefslogtreecommitdiff
path: root/src/board.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/board.cpp')
-rw-r--r--src/board.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/board.cpp b/src/board.cpp
index 877e8c7..a74c5dc 100644
--- a/src/board.cpp
+++ b/src/board.cpp
@@ -35,7 +35,7 @@ Piece createPiece(PieceType type, bool color, bool moved) {
piece.color = color;
piece.moved = moved;
return piece;
-};
+}
void printBoard(Board *b) {
std::string line = " +-----------------+\n";
std::string whiteLetters = " a b c d e f g h\n";
@@ -87,6 +87,9 @@ void printBoard(Board *b) {
assert(b->castle != "");
std::println("Castling: {}", b->castle);
+ std::println("Can enpassant: {}", b->canEnpassant ? "Yes" : "No");
+ std::println("Where enpassant: {}{}", (char)((int)b->enPassant.file + 'A'),
+ 8 - (int)b->enPassant.rank);
}
void PlayMove(Move move, Board *b) {
@@ -98,8 +101,34 @@ void PlayMove(Move move, Board *b) {
assert(false && "capturing friendly piece error");
}
}
- b->pieces[PositionToIndex(move.To)] = piece;
- b->pieces[PositionToIndex(move.From)] = {false, NONE, false};
- return;
-}
+ piece.moved = true;
+ if (piece.type == PAWN || piece2.type == NONE) {
+ b->halfMoveClock = 0;
+ } else {
+ b->halfMoveClock++;
+ }
+ if (piece.type == PAWN && b->canEnpassant && move.To == b->enPassant) {
+ Position capturedPawn = move.To;
+ capturedPawn.rank += piece.color ? 1 : -1;
+ b->pieces[PositionToIndex(capturedPawn)] = {false, NONE, false};
+ }
+
+ b->canEnpassant = false;
+ b->MoveClock++;
+
+ if (piece.type == PAWN) {
+ Position to = move.To;
+ to.rank -= (piece.color ? -2 : 2);
+ if (to == move.From) {
+ b->canEnpassant = true;
+ Position target = move.From;
+ target.rank += piece.color ? -1 : 1;
+ b->enPassant = target;
+ };
+
+ b->pieces[PositionToIndex(move.To)] = piece;
+ b->pieces[PositionToIndex(move.From)] = {false, NONE, false};
+ return;
+ }
+};
int PositionToIndex(Position i) { return i.rank * 8 + i.file; }