Skip to content

Commit

Permalink
Add endgame check for evaluation
Browse files Browse the repository at this point in the history
Change-type: patch
Signed-off-by: Giovanni Garufi <[email protected]>
  • Loading branch information
nazrhom committed Jan 27, 2021
1 parent 5baba43 commit 426e170
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ logFilePath = "./log.txt"

main :: IO ()
main = do
let depth = 5
let depth = 6
processLine depth initialGameState

printAndLog :: String -> IO ()
Expand Down
18 changes: 17 additions & 1 deletion src/Evaluation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ evaluateBoard board@(Board b) =
bishopsq = computeSquare bishopsTable (wb, bb)
rooksq = computeSquare rooksTable (wr, br)
queensq = computeSquare queensTable (wq, bq)
kingsq = computeSquare kingsTable (wk, bk)
kingsq = computeSquare (if isEndGame then kingsEndGameTable else kingsTable) (wk, bk)

isEndGame = case (null wq, null bq) of
(True, True) -> True
(True, _) -> (sum $ map length [bn, bb, br]) <= 1
(_, True) -> (sum $ map length [wn, wb, wr]) <= 1
(_,_) -> False

(wp, bp) = pieceTypeIndexes Pawn board
(wn, bn) = pieceTypeIndexes Knight board
Expand Down Expand Up @@ -100,3 +106,13 @@ kingsTable = V.fromList [
-30,-40,-40,-50,-50,-40,-40,-30
]

kingsEndGameTable = V.fromList [
-50,-40,-30,-20,-20,-30,-40,-50,
-30,-20,-10, 0, 0,-10,-20,-30,
-30,-10, 20, 30, 30, 20,-10,-30,
-30,-10, 30, 40, 40, 30,-10,-30,
-30,-10, 30, 40, 40, 30,-10,-30,
-30,-10, 20, 30, 30, 20,-10,-30,
-30,-30, 0, 0, 0, 0,-30,-30,
-50,-30,-30,-30,-30,-30,-30,-50
]

0 comments on commit 426e170

Please sign in to comment.