From b940e4fc1980d8dafae0fc254ae00fe6a8a4d1b7 Mon Sep 17 00:00:00 2001 From: Matthias Felleisen Date: Sat, 22 Dec 2012 17:30:50 -0500 Subject: [PATCH] made it truly strict, organized data defs --- collects/realm/chapter10/source.rkt | 60 ++++++++++++++++------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/collects/realm/chapter10/source.rkt b/collects/realm/chapter10/source.rkt index a8968d5c55..1a90eb377d 100644 --- a/collects/realm/chapter10/source.rkt +++ b/collects/realm/chapter10/source.rkt @@ -58,22 +58,44 @@ ;; --------------------------------------------------------------------------------------------------- ;; Data +(struct dice-world (src board gt) #:transparent) +;; DiceWorld = (dice-world (U #false Natural) Board GameTree) +;; in (dice-world i b gt) +;; -- if i is a Natural, it is an index for the territory that the player has marked for an attack +;; -- if i is #f, no territory has been marked yet +;; b is the current board +;; gt is the game-tree for the given i and b + (struct game (board player moves) #:transparent) ;; GameTree = (game Board Player [Listof Move]) +;; in (game-tree b p lm) +;; -- b is the current board +;; -- p is the current player +;; -- lm is the list of moves that that player may execute -;; A Player is a Natural in [0, PLAYER#) - -;; A Board is a [List-of Territory] +;; Board = [List-of Territory] ;; the first field in the list is the currently marked territory +;; Player ∈ [0, PLAYER#) | Natural + +(struct move (action gt) #:transparent) +;; Move = (move Action GameTree) +;; in (move a gt) +;; -- a represents the actione to be takem +;; -- gt is the game-tree resulting from that action + +;; Action is one of: +;; -- '() a passing move +;; -- (list Natural Natural) the move where the first attacks the second + (struct territory (index player dice x y) #:transparent) -;; A territory is a (territory Natural Player Dice Number Number) -;; first field is a unique number identifying the territory and its initial location -;; in the board -;; the second field is the player who owns this territory -;; the third field is the number of dice on this board -;; the fourth field is the x coordiate of this territory in pixels -;; the fifth field is the y coordiate of this territory in pixels +;; Territory = (territory Natural Player Dice Integer Integer) +;; in (territory i p d x y) +;; -- i is a unique identifier for the territory; it also determines its initial location +;; -- p is the player who owns this territory +;; -- d is the number of dice on this board +;; -- x is the x coordiate of this territory in pixels +;; -- y is the y coordiate of this territory in pixels ;; Territory Natural -> Territory ;; updates number of dice on territory @@ -85,24 +107,8 @@ (define (territory-set-player t p) (territory (territory-index t) p (territory-dice t) (territory-x t) (territory-y t))) -(struct move (action gt) #:transparent) -;; A Move is a (move Action GameTree) -;; the first field is the action this move represents -;; the second field is the gametree resulting from that move. - -;; an Action is one of -;; -'() a passing move -;; -(list Natural Natural) The move where the first attacks the second - -(struct dice-world (src board gt) #:transparent) -;; A DiceWorld is a (dice-world Natural Board GameTree) -;; the first field is number the territory the current player has marked -;; to attack with #f if no territory has been marked -;; the second is the board -;; the third is the current game-tree - ;; --------------------------------------------------------------------------------------------------- -;; sample game tree for BOOK (NICOLE) +;; sample game tree for BOOK (define b1 (list (territory 1 0 1 'a 'b)