Tic-tac-toe: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: add ! to method name with side effects; move a blank line) |
(→{{header|Racket}}: be more specific about the generality of game.rkt) |
||
Line 4,506: | Line 4,506: | ||
V |
V |
||
+ game.rkt -- Written in Lazy Racket, defines general classes for the game and players. |
+ game.rkt -- Written in Lazy Racket, defines general classes for the game and players. |
||
| Knows nothing about tick-tack-toe |
| Knows nothing about tick-tack-toe, only about zero-sum two-player |
||
| turn-taking games with perfect information in general. |
|||
V |
V |
||
+ tick-tack.rkt -- Written in Racket, implements the tick-tack-toe game. |
+ tick-tack.rkt -- Written in Racket, implements the tick-tack-toe game. |
||
Line 4,565: | Line 4,566: | ||
;; optimal-move :: State -> Move |
;; optimal-move :: State -> Move |
||
;; Choses the optimal move. |
;; Choses the optimal move. |
||
;; If several |
;; If several equivalent moves exist -- choses one randomly. |
||
(define/public ((optimal-move look-ahead) S) |
(define/public ((optimal-move look-ahead) S) |
||
(! (argmax (λ (m) (! (minimax (game-tree S m look-ahead)))) |
(! (argmax (λ (m) (! (minimax (game-tree S m look-ahead)))) |