Gamesman - The "Shall We Play a Game?" Project
     
 
   
>>
     Background
   Overview
   Quick Guide
   Definitions
   Files
   Implementation
   Rule Changes
   Simple Graphics
   FAQ

 

 
    
 
   
 
   
 
   
 
Assignment > Implementation

Implementation

There are five data abstraction procedures and six key procedures you will need to implement for each game: make-position, make-board, get-board, get-num-rows, get-num-cols, whose-move, do-move, primitive-position, print-position, print-help and generate-moves. These are described below with Degree of Difficulty (DoD listed, from 1-10) and when they are due. As always, take a look at m1210.scm and mtttt.scm to see how those games do it.

Getting Started (Dod 0) - Due at Checkoff 0

In order to get started, enter the values for *game-name*, *group-members*, the arguments to name-game-pieces, and rename the template file to the appropriate mxxx.scm (mnorthcotts.scm, mkonane.scm, msurround.scm, mknights.scm). Show this to your TA for your second checkoff 0 point.

make-position (DoD 2) - Due at Checkoff 1

Takes a player (e.g. w or b) and a board (consists of number of rows, number of columns, position of all pieces, and perhaps any extra game-specific data) and returns the position. A position is sentence of player and board.

make-board (DoD 2) - Due at Checkoff 1

Takes number of rows, number of columns, position of all pieces, and perhaps any extra game-specific data and returns the board.

get-board (DoD 2) - Due at Checkoff 1

Takes a position and returns the board.

get-num-rows (DoD 2) - Due at Checkoff 1

Takes a position and returns the number of rows of the board.

get-num-cols (DoD 2) - Due at Checkoff 1

Takes a position and returns the number of columns of the board.

whose-move (DoD 2) - Due at Checkoff 1

Takes a position and returns the name of the piece whose turn it is. IMPORTANT: this name must be the same as one of the two names you used when you called name-game-pieces. In other words, if you called name-game-pieces like this: (name-game-pieces "Turkey" "Chicken") then whose-move must return either "Turkey" or "Chicken." It cannot return "Pork."

print-position (DoD 2) - Due at Checkoff 1

Takes a position and prints it (using display, newline and/or format) in a visually appealing textual way. How you print it is up to you, but your goal is to have it look as nice as possible. Additionally, feel free to include other information about the game when you print the position, such as whose turn it is as well as which rules are in play. We have not shown you how this works yet, but when you find out feel free to come back to print-position and add to what it does.

print-help (DoD 2) - Due at Checkoff 1

Takes no arguments and prints (using display, newline and/or format) the rules and objective of the game. For now, just have print-help print the rules for the standard game. Later, when we show you how to change the rules of your game, the output of print-help will change depending on which rules you have in play.

do-move (DoD 4) - Due at Checkoff 2

Takes two arguments. The first is the position and the second is the move. It should return the position that results from making the move. Assume that both the position and move are legal. No error-checking should be done. If you are encoding whose turn it is as part of the position, do not forget to "flip" this value. We guarantee that the move given to do-move will be one of the moves created by generate-moves for the position given to do-move. For those implementing konane this function has a DoD of 10, while generate-moves has a Dod of 4.

primitive-position (DoD 6) - Due at Checkoff 2

A "primitive" position is one that ends the game. In Tomorrow's Tic-Tac-Toe, for example, a primitive position is one having three-in-a-row, or one with no empty spaces. The primitive-position function takes a position and returns a one-letter word or #f:

  • w iff the position represents a win for the player whose turn it is
  • t iff the position represents a tie for the player whose turn it is
  • l iff the position represents a lose for the player whose turn it is
  • #f iff none of the above -- meaning that the game is not over.

When primitive-position returns a non-#f value, Gamesman will know that the game is over.

generate-moves (DoD 10) - Due at Checkoff 2

Takes a position and returns a sentence/list of all the moves that can be made from that position by the piece whose turn it is. Assume the position is valid; we guarantee that the position given to generate-moves will be either the initial position or a position returned by do-move.

 

[Dan Garcia icon] [Department of Computer Science] [Official Website for the University of California, Berkeley]


Gamesman ©2003 Dan Garcia. All rights reserved.
Site design by Steven Chan. Site maintained by Hesam Samimi.