FEN: 8/8/8/8/2K5/5Q2/6PP/4k3 w - - 0 100 (I use 100 to ensure my engine plays with the endgame PST :) )
Here are the best moves found at each depth with a score when I don't return the score directly from the TT (I still use the best move found in the TT for ordering). The engine proceeds directly to mate in the least number of moves. I annotated "good" if the move did not length mate, and "bad" if it did lengthen mate.
Code: Select all
Best move (1) [11.8] Kc4-d5 bad
Best move (2) [11.7] Qf3-e3 bad
Best move (3) [11.8] Qf3-e3 bad
Best move (4) [11.8] Kc4-d4 good
Best move (5) [11.9] Qf3-d3 bad
Best move (6) [11.9] Kc4-d4 good
Best move (7) [11.95] Ph2-h4 good
Best move (8) [999.93] Kc4-d4 good (mate)
Code: Select all
Best move (1) [11.8] Kc4-d5 bad
Best move (2) [11.7] Qf3-e3 bad
Best move (3) [11.8] Qf3-e3 bad
Best move (4) [11.8] Kc4-d4 good
Best move (5) [11.9] Qf3-d3 bad
Best move (6) [11.9] Qf3-d5 bad
Best move (7) [12] Pg2-g3 good
Best move (8) [999.93] Kc4-d4 good (mate)
Best move (9) [999.95] Kc4-b3 good (mate)
Best move (10) [999.95] Kc4-c5 bad (longer mate)
Best move (11) [999.95] Kc4-c5 bad (longer mate)
Code: Select all
(if (is-king-in-check? b)
(fx+ MIN-SCORE depth)
0)
Here's the code to read the TT entry. I think it's typical - using EXACT, ALPHA and BETA types.
Code: Select all
;; Returns (values score move). If no matching entry found, both score and move are #f
(define (read-tt-entry key draft alpha beta)
(let ([ entry (vecref tt-table (hash-index key)) ])
(if (and entry (fx= key (tt-zobrist-key entry)))
;; Entry found, and it matches the key
(let ([ best-move (tt-best-move entry) ])
(if (fx>= (tt-draft entry) draft)
;; We have sufficient draft
(let ([ score (tt-score entry) ]
[ type (tt-type entry) ])
(cond [ (fx= NODE-EXACT type) (values score best-move) ]
[ (and (fx= NODE-ALPHA type) (fx<= score alpha)) (values alpha best-move) ]
[ (and (fx= NODE-BETA type) (fx>= score beta)) (values beta best-move) ]
[ else (values #f best-move) ]))
;; Insufficient draft, we can't use the score, but return
;; best move
(values #f best-move)))
;; Nothing found
(values #f #f))))