···174174}
175175176176fn en_passant_is_valid(game: Game, position: Int, new_position: Int) -> Bool {
177177- case can_move(position, new_position, game.attack_information) {
178178- False -> False
179179- True -> {
180180- let captured_pawn_position =
181181- board.position(
182182- file: board.file(new_position),
183183- rank: board.rank(position),
177177+ let captured_pawn_position =
178178+ board.position(file: board.file(new_position), rank: board.rank(position))
179179+180180+ case game.attack_information.in_check {
181181+ False ->
182182+ move_is_valid_with_pins(position, new_position, game.attack_information)
183183+ True ->
184184+ // If the king is in check by the pawn we are capturing, then en passant
185185+ // is valid. It is also valid if moving the pawn to its new location blocks
186186+ // the existing check.
187187+ {
188188+ list.contains(
189189+ game.attack_information.check_block_line,
190190+ captured_pawn_position,
184191 )
185185- !in_check_after_en_passant(game, position, captured_pawn_position)
186186- }
192192+ || list.contains(game.attack_information.check_block_line, new_position)
193193+ }
194194+ && move_is_valid_with_pins(
195195+ position,
196196+ new_position,
197197+ game.attack_information,
198198+ )
187199 }
200200+ && !in_check_after_en_passant(game, position, captured_pawn_position)
188201}
189202190203/// En passant needs to be checked slightly different to other moves. For example,
+9
test/starfish_test.gleam
···133133 )
134134}
135135136136+// Ensure en passant blocking check is valid
137137+pub fn perft_extra_position1_test_() {
138138+ use <- Timeout(1_000_000)
139139+ use <- pocket_watch.callback("extra position 1", print_time)
140140+ perft_all("r1b1kbnr/p1p1pppp/p1K3q1/3pP3/8/8/PPP1PPPP/RNBQ1BNR w kq d6 0 1", [
141141+ 5, 157, 4146, 128_984, 3_660_806,
142142+ ])
143143+}
144144+136145fn test_apply_move(
137146 starting_fen: String,
138147 moves: List(move.Move(move.Legal)),