Comp210: Principles of Computing and Programming
Fall 2004 -- Supplied Functions    


Here is the documentation of the functions that are defined in game-control.zo:

Monitor the WebCT discussions to see if a new version of game-control.zo is posted!  The version date & number of the code prints out after load("game-control.zo") executed.

Board:  This structure is used to represent a square game board.

;; Board is a structure that represents a game board that holds pieces
;; of different values.
;; size = size of row = size of col  (square board)
;; rows = list of lists of length size holding player id values.  
;; free = # of open cells = size * size initially
;; The following functions assume that the given location is valid.
;; getSquare: Loc --> any  returns the value held at the given location.
;; setSquare!: Loc any --> void mutuates the given location to hold the given value.
(define-struct Board (size rows free getSquare setSquare!))
Loc:  This structure is used to represent a row-column position on the board.
;; Loc is a structure representing a location on a Board.  
;; row and col are the corresponding row and column values 
;; for the location.
(define-struct Loc (row col))

 

EMPTY-CELL: This value corresponds to the values stored in the board signifying empty squares.   Do not use a different value for an empty square as the rest of the system relies on this value. 

 

Opponent:  a structure to encapsulate a player's name and their playFn

;; Opponent is a structure that represents an opponent (player) in a game.
;; (make-Opponent string (Board num natnum (-->num) --> Loc))
;; where name is a string that is the name of the opponent.
;; playFnFac is the factory for the playFn function the opponent 
;; is going to use to calculate their moves.
(define-struct Opponent (name playFnFac))

 

runGame:  a function that runs a game with two opponents with the given game parameters.  Note that the playFns get handed a copy of the board, so they are free to mutate it as they please.

;; runGame: natnum natnum num Opponent Opponent --> void
;; (runGame size minLength maxTime opp1 opp2) will 
;; start a game using opp1 and opp2 as players.  
;; The board will be size x size.
;; minLength will be the minimum length of a chain to win
;; maxTime will be the maximum amount of time a player is given to make a move.
;; opp1 will move first.
(define (runGame size minLength maxTime opp1 opp2)
    ...)

 

load-playFnFac:  A utility function loads a Scheme file and returns the playFnFac defined inside the file.  This enables you to play two playFn's against each other because you can take the return value of this function and define it to be a different name or run the factory more than once to create two separate playFn's.

;; load-playFnFac: string --> playFnFac
;; (load-playFnFac filename) loads the given file
;; and returns the function inside that file called 
;; "playFnFac".  If playFnFac is not found in the file, 
;; returns a playFnFac that returns
;; a playFn that always returns an illegal move.
(define (load-playFnFac filename)
   ...)

 

Loc-equal?: A utility function returns true if the two given Loc structures refer to the same row and column.  Returns false otherwise.  Note that equal? will not work on Loc structures.

;; Loc-equal?: Loc Loc --> boolean
;; returns true if the two location objects
;; are the same, i.e. have the same contents.
(define (Loc-equal? l1 l2)
     ...))
 

make-empty-board: A factory function to create a new Board structure of the given size, n, and filled with the value representing an empty cell, EMPTY-CELL.


;; make-empty-board: natnum --> Board
;; returns an empty Board which is
;; filled with EMPTY-CELL values.
(define (make-empty-board n)
    ...)

make-non-empty-board: A factory function to create a new Board structure of the given size, n, using the supplied list-of-lists-of-any.  The value used in the supplied list-of-lists to represent an empty square, emptyVal, is replaced with the EMPTY-CELL value.   Use this function to create test scenarios for your playFn.
;;make-non-empty-board: list-of-list-of-any --> Board
;; Returns a Board of the same size as the given list-of-lists
;; and filled with the same values.
;; The given list-of-lists is assumed to be a square layout.
(define (make-non-empty-board rows emptyVal)
    ...)
 

copy-board: A factory  function to copy the given Board structure. 

;;copy-board: Board --> Board
;; Returns a copy of the given Board.
(define (copy-board board)
    ...)
 

make-timeLeftFn: A factory function that generates a no-parameter timeLeftFn lambda that returns the number of seconds since make-timeLeftFn was called to create it.    Use this function to supply the timeLeftFn for playFn when testing.

;; make-timeLeftFn: num --> (--> num)
;; A factory for a timeLeftFn function. 
;; Given a max number of seconds, max, make-timeLeftFn 
;; returns a no-parameter lambda, that when executed, gives
;; the number of seconds left until max seconds have expired 
;; since the lambda was created by make-timeLeft.
;; The returned lambda of this factory is the type given as an input
;; parameter when the system calls a player's playFn.   Note that a 
;; timeLeftFn will not itself cause the termination of a player's turn.
(define (make-timeLeftFn max)
    ...)

 


Last Revised Saturday, 13-Nov-2004 21:59:14 CST

©2004 Stephen Wong and Dung Nguyen