tangled
alpha
login
or
join now
gearsco.de
/
starfish
2
fork
atom
A chess library for Gleam
2
fork
atom
overview
issues
pulls
pipelines
Fix move generation for sliding pieces
gearsco.de
6 months ago
7a6db26a
1e331a95
+6
-6
2 changed files
expand all
collapse all
unified
split
src
starfish
internal
move.gleam
test
starfish_test.gleam
+5
-4
src/starfish/internal/move.gleam
···
159
159
sliding_moves(
160
160
game,
161
161
position,
162
162
-
sliding_moves_in_direction(game, position, direction, moves),
162
162
+
sliding_moves_in_direction(game, position, position, direction, moves),
163
163
directions,
164
164
)
165
165
}
···
167
167
168
168
fn sliding_moves_in_direction(
169
169
game: Game,
170
170
+
start_position: Int,
170
171
position: Int,
171
172
direction: Direction,
172
173
moves: List(Move(Legal)),
···
174
175
let new_position = direction.in_direction(position, direction)
175
176
case iv.get(game.board, new_position) {
176
177
Ok(board.Empty) ->
177
177
-
sliding_moves_in_direction(game, new_position, direction, [
178
178
-
Move(from: position, to: new_position),
178
178
+
sliding_moves_in_direction(game, start_position, new_position, direction, [
179
179
+
Move(from: start_position, to: new_position),
179
180
..moves
180
181
])
181
182
Ok(board.Occupied(colour:, ..)) if colour != game.to_move -> [
182
182
-
Capture(from: position, to: new_position),
183
183
+
Capture(from: start_position, to: new_position),
183
184
..moves
184
185
]
185
186
Ok(board.Occupied(_, _)) | Error(_) -> moves
+1
-2
test/starfish_test.gleam
···
87
87
use <- Timeout(1_000_000)
88
88
use <- pocket_watch.callback("initial position", print_time)
89
89
perft_all(starfish.starting_fen, [
90
90
-
20,
91
91
-
// 400, 8902, 197_281, 4_865_609, 119_060_324,
90
90
+
20, 400, 8902, 197_281, 4_865_609, 119_060_324,
92
91
])
93
92
}
94
93