RosettaCodeData/Task/Tic-tac-toe/Racket/tic-tac-toe-1.rkt
Ingy döt Net 776bba907c Sync
2013-10-27 22:24:23 +00:00

20 lines
652 B
Racket
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#lang lazy
(provide minimax)
(define (minimax tree)
(! (let minimax ([node tree] [α -inf.0] [β +inf.0] [max-player #f])
(cond
[(number? node) node]
[(empty? node) 0.0]
[max-player
(let next ([x node] [α α])
(if (or (empty? x) (<= β α))
α
(next (cdr x)
(max α (minimax (car x) α β (not max-player))))))]
[else
(let next ([x node] [β β])
(if (or (empty? x) (<= β α))
β
(next (cdr x)
(min β (minimax (car x) α β (not max-player))))))]))))