From 4c8fdfa3b48200e48f33962137287c01f369346c Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Sun, 2 Feb 2025 23:13:37 +0100 Subject: [PATCH] implemented en passant in legal moves --- cpp/src/pieces/pawn.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cpp/src/pieces/pawn.cpp b/cpp/src/pieces/pawn.cpp index 91b182f..8fae3f6 100644 --- a/cpp/src/pieces/pawn.cpp +++ b/cpp/src/pieces/pawn.cpp @@ -29,6 +29,19 @@ std::vector pawn_moves(const Board& b, const Coords xy) { } } + // -- Capture en passant + if (b.en_passant_target != -1) { + Coords c = Coords::from_index(b.en_passant_target); + int dy = my_colour == Colour::White ? -1 : 1; + if (c.y == xy.y + dy && (c.x == xy.x - 1 || c.x == xy.x + 1)) + ret.push_back(Move{ + xy.to_index(), + c.to_index(), + .is_capturing = true, + .en_passant = true + }); + } + // -- Promotion bool is_on_starting_rank = my_colour == Colour::White ? xy.y == 1 : xy.y == 6;