;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname ttt-server) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) (require 2htdp/universe) ; A Bundle is ; (make-bundle Universe [Listof Mail] [Listof IWorld]) ; A Mail is a (make-mail IWorld SExp) (define board0 (list false false false)) ;; Universe IWorld -> Bundle (define (join u iw) (cond [(empty? (ttt-players u)) (make-bundle (make-ttt (list iw) board0 'x) empty empty)] [(empty? (rest (ttt-players u))) (make-bundle (make-ttt (cons iw (ttt-players u)) board0 'x) (list (make-mail (first (ttt-players u)) board0)) empty)] [else (make-bundle u empty (list iw))])) ;; Universe IWorld Msg -> Bundle (define (process u iw msg) ;; Update the board ;; Switch players, sending the new state of the board. (make-bundle u empty empty)) ;; A Universe is a (make-ttt [Listof IWorld] Board Letter) (define-struct ttt (players board turn)) (define u0 (make-ttt empty (list false false false) 'x)) (universe u0 (on-new join) (on-msg process)) ;; Players, Board, Who's turn is it,