feat(movegen): add pseudo-legal and legal move generation with perft

This commit is contained in:
dualfroz committed 2026-08-24 15:50:00 +02:00
1 parent c312e5d2df
commit 42c792d21c
2 files changed
+173

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
package gambit
object Perft:
def perft(pos: Position, depth: Int): Long =
if depth == 0 then 1L
else
val moves = new MoveList()
MoveGen.generateLegal(pos, moves)
if depth == 1 then moves.size.toLong
else
var nodes = 0L
var i = 0
while i < moves.size do
val m = moves(i)
val undo = pos.make(m)
nodes += perft(pos, depth - 1)
pos.unmake(m, undo)
i += 1
nodes
def divide(pos: Position, depth: Int): List[(String, Long)] =
val moves = new MoveList()
MoveGen.generateLegal(pos, moves)
val out = List.newBuilder[(String, Long)]
var i = 0
while i < moves.size do
val m = moves(i)
val undo = pos.make(m)
val count = if depth <= 1 then 1L else perft(pos, depth - 1)
pos.unmake(m, undo)
out += (Move.uci(m) -> count)
i += 1
out.result()