Skip to content

Commit bfd9bf4

Browse files
feat(draw by fifty moves) : DONE
- create a new function to check if it's a draw by fifty moves rule or not. - this will help UI devs to show exact reason of a draw.
1 parent 85c049e commit bfd9bf4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: src/chess.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1086,16 +1086,20 @@ export class Chess {
10861086
return this._getPositionCount(this.fen()) >= 3
10871087
}
10881088

1089-
isDraw() {
1089+
isDrawByFiftyMoves(): boolean {
1090+
return this._halfMoves >= 100 // 50 moves per side = 100 half moves
1091+
}
1092+
1093+
isDraw(): boolean {
10901094
return (
1091-
this._halfMoves >= 100 || // 50 moves per side = 100 half moves
1095+
this.isDrawByFiftyMoves() ||
10921096
this.isStalemate() ||
10931097
this.isInsufficientMaterial() ||
10941098
this.isThreefoldRepetition()
10951099
)
10961100
}
10971101

1098-
isGameOver() {
1102+
isGameOver(): boolean {
10991103
return this.isCheckmate() || this.isStalemate() || this.isDraw()
11001104
}
11011105

0 commit comments

Comments
 (0)