Skip to content

Instantly share code, notes, and snippets.

@lojic
Created February 18, 2021 04:53
Show Gist options
  • Save lojic/9f78e7789dc2829f74f776044e50dd3e to your computer and use it in GitHub Desktop.
Save lojic/9f78e7789dc2829f74f776044e50dd3e to your computer and use it in GitHub Desktop.
(define (move-iterator! b
#:order-moves? [ order-moves? #t ]
#:tt-move [ tt-move #f ]
#:quiet-moves? [ quiet-moves? #t ])
(define do-gen #t)
(define qhead #f)
(define qi #f)
(define qmoves #f)
(define thead #f)
(define ti #f)
(define tmoves #f)
(define (gen-moves)
(generate-moves! b #:quiet-moves? quiet-moves?)
(set! qhead (quiet-head b))
(set! qi 0)
(set! qmoves (quiet-moves b))
(set! thead (tactical-head b))
(set! ti 0)
(set! tmoves (tactical-moves b)))
(define (get-tt-move)
(set! func get-tactical-move)
(if tt-move
tt-move
(begin
(set! tt-move 0) ; To allow comparing with fx= below
(get-tactical-move))))
(define (get-tactical-move)
(when do-gen
(set! do-gen #f)
(gen-moves)
(when order-moves? (order-moves! b)))
(cond [ (fx<= ti thead)
(let ([ m (vecref tmoves ti) ])
(set! ti (fx+ 1 ti))
(if (fx= m tt-move)
(get-tactical-move)
m)) ]
[ (set! func get-quiet-move)
(get-quiet-move) ]))
(define (get-quiet-move)
(cond [ (fx<= qi qhead)
(let ([m (vecref qmoves qi) ])
(set! qi (fx+ 1 qi))
(if (fx= m tt-move)
(get-quiet-move)
m)) ]
[ else #f]))
(define func get-tt-move)
(λ ()
(func)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment