A chess library for Gleam
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Ensure en passant blocks check if the pawn moves into the check line

+31 -9
+22 -9
src/starfish/internal/move.gleam
··· 174 174 } 175 175 176 176 fn en_passant_is_valid(game: Game, position: Int, new_position: Int) -> Bool { 177 - case can_move(position, new_position, game.attack_information) { 178 - False -> False 179 - True -> { 180 - let captured_pawn_position = 181 - board.position( 182 - file: board.file(new_position), 183 - rank: board.rank(position), 177 + let captured_pawn_position = 178 + board.position(file: board.file(new_position), rank: board.rank(position)) 179 + 180 + case game.attack_information.in_check { 181 + False -> 182 + move_is_valid_with_pins(position, new_position, game.attack_information) 183 + True -> 184 + // If the king is in check by the pawn we are capturing, then en passant 185 + // is valid. It is also valid if moving the pawn to its new location blocks 186 + // the existing check. 187 + { 188 + list.contains( 189 + game.attack_information.check_block_line, 190 + captured_pawn_position, 184 191 ) 185 - !in_check_after_en_passant(game, position, captured_pawn_position) 186 - } 192 + || list.contains(game.attack_information.check_block_line, new_position) 193 + } 194 + && move_is_valid_with_pins( 195 + position, 196 + new_position, 197 + game.attack_information, 198 + ) 187 199 } 200 + && !in_check_after_en_passant(game, position, captured_pawn_position) 188 201 } 189 202 190 203 /// En passant needs to be checked slightly different to other moves. For example,
+9
test/starfish_test.gleam
··· 133 133 ) 134 134 } 135 135 136 + // Ensure en passant blocking check is valid 137 + pub fn perft_extra_position1_test_() { 138 + use <- Timeout(1_000_000) 139 + use <- pocket_watch.callback("extra position 1", print_time) 140 + perft_all("r1b1kbnr/p1p1pppp/p1K3q1/3pP3/8/8/PPP1PPPP/RNBQ1BNR w kq d6 0 1", [ 141 + 5, 157, 4146, 128_984, 3_660_806, 142 + ]) 143 + } 144 + 136 145 fn test_apply_move( 137 146 starting_fen: String, 138 147 moves: List(move.Move(move.Legal)),