-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.fr
29 lines (25 loc) · 1.07 KB
/
test.fr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import frech.Daten
import frech.Eval
import frech.FEN
import frech.Protocol
import frech.Strategies
import Data.HashMap
import Data.JSON(toJSON)
gs = initialGS.performUnsafe
foldMVs pos mvs = foldM mkMove pos mvs
mkMove p a = applyMove p <$> case unAlgebraic (moves p) a of Just m -> Right m; _ -> Left a
mtdf :: GameState -> Int -> IO Variation
mtdf gs d = do
let pv = negaMax gs empty false 3 whiteIsMate blackIsMate
mtRepeat gs d pv whiteIsMate blackIsMate
where
mtRepeat :: GameState → Int → Variation → Int → Int → IO Variation
mtRepeat gs d pv lower upper = do
let g = pv.val
stdout.printf "# mtRepeat d=%d g=%d lower=%d upper=%d nodes=%d moves=%s\n" d g lower upper pv.nodes (show pv.moves)
if lower >= upper then pure pv
else do
let r = negaMax gs pv.hash false d (pv.val-1) (pv.val+1)
let upper' = if r.val >= pv.val then pv.val else upper
let lower' = if r.val < pv.val then pv.val else lower
mtRepeat gs d r lower' upper'