mirror of
https://github.com/tiyn/yeschess.git
synced 2025-10-19 06:11:22 +02:00
engine: engine now correctly uses the negamax algorithm
NegaMax is a simplified version of the MiniMax algorithm that doesn't need different subroutines for the different colors. The testcases were selected and extended. Evaluation now has values for draws and wins.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import einheit
|
||||
import algorithm
|
||||
|
||||
import ./chess
|
||||
import ./engine
|
||||
@@ -12,7 +11,7 @@ testSuite GameTest of TestSuite:
|
||||
method setup() =
|
||||
self.game = initGame()
|
||||
|
||||
method testPieceEval() =
|
||||
method testPieceEvalStalemate() =
|
||||
self.game = initGame([
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, WKing, 0, 0, 0, 0,
|
||||
@@ -37,10 +36,28 @@ testSuite GameTest of TestSuite:
|
||||
0, 0, 0, 0, 0, BKing, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
], Color.Black)
|
||||
var mTree = self.game.spanMoveTree(2)
|
||||
var mTree = self.game.spanMoveTree(1)
|
||||
self.check(mTree.children == [])
|
||||
|
||||
method testManualMiniMaxEval() =
|
||||
method testBestMoveProm() =
|
||||
self.game = initGame([
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, WKing, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, WPawn, 0, BKing, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
], Color.White)
|
||||
var testBestMove = self.game.bestMove(2)
|
||||
self.check(testBestMove.start != 0)
|
||||
self.check(indToField(testBestMove.start) == "e7")
|
||||
self.check(indToField(testBestMove.dest) == "e8")
|
||||
|
||||
|
||||
|
||||
method testBestMoveStopProm() =
|
||||
self.game = initGame([
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, WKing, 0, 0, 0, 0,
|
||||
@@ -51,25 +68,41 @@ testSuite GameTest of TestSuite:
|
||||
0, 0, 0, 0, WPawn, BKing, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
], Color.Black)
|
||||
var mTree = self.game.spanMoveTree(2)
|
||||
var evaluation = mTree.minimax()
|
||||
self.check(evaluation == 0)
|
||||
|
||||
method testBestMove() =
|
||||
var testGame = initGame([
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, WKing, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, WPawn, BKing, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
], Color.Black)
|
||||
var testBestMove = testGame.bestMove(2)
|
||||
var testBestMove = self.game.bestMove(2)
|
||||
self.check(testBestMove.start != 0)
|
||||
self.check(indToField(testBestMove.start) == "c7")
|
||||
self.check(indToField(testBestMove.dest) == "d7")
|
||||
|
||||
method testBestMoveTacticBlack() =
|
||||
self.game = initGame([
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, WRook, 0, WKing, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, WPawn, 0, 0, 0, 0, 0,
|
||||
0, BPawn, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, BRook, 0, 0, 0, BKing, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
], Color.Black)
|
||||
var testBestMove = self.game.bestMove(2)
|
||||
self.check(testBestMove.start != 0)
|
||||
self.check(indToField(testBestMove.start) != "g5" or indToField(testBestMove.dest) != "f4")
|
||||
|
||||
method testBestMoveTacticWhite() =
|
||||
self.game = initGame([
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, WRook, 0, WKing, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, WPawn, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, BPawn, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, BRook, 0, 0, 0, BKing, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
], Color.White)
|
||||
var testBestMove = self.game.bestMove(2)
|
||||
self.check(testBestMove.start != 0)
|
||||
self.check(indToField(testBestMove.start) != "g4" or indToField(testBestMove.dest) != "f5")
|
||||
|
||||
|
||||
when isMainModule:
|
||||
einheit.runTests()
|
||||
|
Reference in New Issue
Block a user