feat(rules): add draw detection

This commit is contained in:
dualfroz committed 2026-08-25 19:15:00 +02:00
1 parent 2a9bf0c22f
commit f465bdecae
1 file changed
+24
+24
View File
@@ -0,0 +1,24 @@
package gambit
object Draw:
def isFiftyMove(pos: Position): Boolean = pos.halfmove >= 100
def isInsufficientMaterial(pos: Position): Boolean =
var minors = 0
var sq = 0
while sq < 128 do
if Square.onBoard(sq) then
Piece.typeOf(pos.board(sq)) match
case Piece.Pawn | Piece.Rook | Piece.Queen => return false
case Piece.Knight | Piece.Bishop => minors += 1
case _ => ()
sq += 1
minors <= 1
def isThreefold(history: collection.Seq[Long], current: Long): Boolean =
var count = 0
var i = 0
while i < history.length do
if history(i) == current then count += 1
i += 1
count >= 3