Introduction to Computer Science I by James Tam Return to the course web page

CPSC 231: Assignment 6 (Worth 6%) Friday June 11

 

New Concepts to be applied for the assignment

  1. Two dimensional arrays

  2. Implementing a solution for a problem with a higher level of difficulty.

Star Trek1

It's hard to believe but the "Trek" franchise has been around for almost 40 years.  Production of the first  episode "The Cage" began in late 1964.   It was given a budget by NBC of $640,000 and produced by Desilu Studios (which was since taken over by Paramount Studios).   Since that historic date, Star Trek has become a part of television and motion picture history and includes an six separate TV series and ten motion pictures.

The ship that started it all!

Grading

Your mission for this assignment

For this assignment you are to implement a simple Star Trek game.  The Trek galaxy (i.e., the milky way) will be modeled with a nine-by-nine two-dimensional array of characters.   In the full game each array element (called a "sector") can contain the characters: 'U', 'F', '*', '@', 'D', 'E' or a space.  The player's ship will be represented by a 'U' while the computer controlled ship is represented by a 'F'.    When the game starts, the human player's starship will always start off in the same location (row 8, column 8) next to the "Terran sector" where the earth is located, coordinates (9,9).    The location of the other objects in the galaxy will also be same every time that the game is started.  (See Figure 1 for the initial starting configuration of the Galaxy).   In the assignment  directory there some Pascal source code that will automatically initialize the galaxy (along with other important variables) for you.

Figure 1: The starting locations for objects in the milky way galaxy.

Legend for the elements in the galaxy:

  1. U: The player's star ship (The United Federation of Planets).
  2. F: The computer-controlled star ship (The Ferengi Alliance)
  3. *:  A star
  4. @: A spatial anomaly
  5. D: The location of the dilithium
  6. E: The player's home sector (the Terran sector which contains the earth).
  7. Spaces denote empty sectors.

Ships are propelled using a faster than light mechanism known as "space warping" or warp speed for short.  Time passes in the game on a turn by turn basis.  Each turn is broken down into three sub-turns and occur in the following order: 1) Player's movement 2) The spatial anomaly moves 3) The ferengi ship moves.  The goal of the game is to go to the sector that contains the dilithium and bring it back to the earth (game is won).   Along the way spatial anomalies may appear and destroy the ship (game is lost) or ferengi raiders may try to steal the dilithium (the player must get the dilithium back).

Grading: Working submissions

Basic assignment "C+"

    1) A ship can travel a maximum of one sector per turn.

Figure 2: Ships can warp to adjacent sectors.

2) Ships cannot travel onto sectors that contain stars (*) or the earth (E).  If the player tries to move his or her ship onto a sector that is occupied with one of these objects an appropriate error message will be displayed (which will differ slightly for each of these cases).

3) Ships cannot travel beyond the bounds the galaxy.  If the player tries to warp outside of the milky way, the program will show another error message indicating that this is not possible.

4) The player can "pass" on moving his or her ship during a turn by entering the coordinates where the ship currently resides.

Extra features:

Implementing each of the extra features listed below will yield a grade increase of one "step" (e.g., "C+" to "B-").  Implementing all six features may result in a maximum grade of A+ (assuming that other submission requirements, such as coding style, have been met).  Unless otherwise noted these extra features can be implemented in any order that you wish.

  1. Expanded cheat mode.  When cheat mode is invoked the player will have two options: 1) To toggle the debugging messages (as described above) 2) To enter (e)dit mode.  Edit mode will allow the player to edit any of the sectors and change them to one of the following characters: *, D or a space.  Although the player can edit sectors that don't contain these characters unpredictable results can occur (e.g., if the player changes the square containing the ferengi ship to a space, the ferengi ship will temporarily disappear only to reappear the next time that it moves).   Changing a sector that does contain one of these characters to another one these characters should work as normal, it is only when the player tries to edit an object that moves when strange results start occurring.

  2. Wormhole.  A wormhole is a "tunnel" is space that connects two points.  Each of these two points are invisible so that the player won't know that a sector contains a wormhole until his or her ship has entered it.  (Moving your ship onto a sector containing a wormhole causes the ship to enter the wormhole).  Entering the wormhole at one point allows for reciprocal and near-instantaneous travel across distant sectors of space.  The locations of the "openings" of the wormhole will be at sector (3, 3) and (9, 7).  When the player's ship enters one of these sectors a message will be displayed onscreen indicating that a wormhole has been entered and the ship's coordinates will now be changed to the location of the other wormhole.  The galaxy will then be displayed showing the player's ship at the new location.   If the player passes on his or her movement the next turn then the ship will again enter the wormhole and it will end up at its original location.

Figure 3: You won't know there is a wormhole there until you've already entered it
  1. Spatial anomaly:  It starts in sector (5, 4), represented by the '@' character, but it will randomly move around the galaxy.  After player has moved (or has passed on his or her move), the program will randomly generate a new set of coordinates for the anomaly.  The new location can be on any empty sector in the galaxy or the sector that is occupied by the player's ship.   The program will continue generating new coordinate pairs until the resulting sector is either empty or contains the player's ship. A spatial anomaly is similar to a wormhole in that both are "rifts" in space but it is less benign: if the player's ship moves into a spatial anomaly or if a spatial anomaly forms on top of the player's ship, the game is lost and the program immediately ends with an appropriate error message displayed onscreen.

Figure 4: A spatial anomaly has formed on top of your ship!
  1. Ferengi:  "The Ferengi have a culture which is based entirely upon commerce. They follow a code of conduct known as "The Ferengi Rules of Acquisition." These rules ordain conduct such as "Never place family before business."2   Their ship is computer-controlled and starts out in sector (1, 1), represented by the 'F' character.   Each turn the ferengi ship will move a maximum of one sector.    This value will be determined by randomly generating a delta for the row and column coordinates of: -1, 0 or 1.  That is, the row and column coordinate can go up by one, down by one or not change.  A separate delta is generated for the row and column and added to the current set of coordinates for the ferengi ship.   If the resulting sector is unoccupied and within the bounds of the galaxy then the ferengi ship will move there.  The program will continue generating a set of delta's until an empty destination sector has been found.  The ferengi ship is not effected by the wormhole or spatial anomaly and will not move onto sectors which contain objects such as stars, the dilithium, the earth or the player's ship.  It will only move onto sectors that contain a space.

   Figure 5: A contract is a contract is a contract...but only between ferengi!
  1. Dilithium:  Although the dilithium shows up in the other versions of the game, with this feature you can pick up the dilithium by moving onto the sector that contains it (1, 4).  At this point the game will tell the player that his or her ship is now carrying the dilithium and they the player should move their ship back to the earth.  Each time that the galaxy is displayed the game will indicate that the player is carrying the dilithium.  The player wins the game if their ship is carrying the dilithium and it is moved to a sector that is adjacent to the earth.
 

  Figure 6: The positive conclusion of the game.
  1. Ferengi raiders (to get credit for this feature you must have first implemented features 4 & 5).  If your ship is carrying the dilithium the ferengi will now steal it if they are adjacent to your ship.  When this occurs a message will be displayed each time that the galaxy is displayed indicating that the ferengi have the dilithium.  The player can get the dilithium back if they move their ship next to the ferengi ship during the movement phase.  If the ferengi's randomly generated coordinates result in a destination that is still adjacent to the player's ship then the ferengi will steal the dilithium yet again.  If the ferengi's randomly generated coordinates result in a destination that is still not adjacent to the player's ship then the player retains the dilithium.
U    
     
    F
 
U    
  F  
     
 
U    
  F  
     
 
U    
    F
     
Player has dilithium   Ferengi steals dilithium   Player stays on square and retakes dilithium   Ferengi ship moves off (player keeps dilithium)

Grading: Non-working submissions

D submissions:

The student has invested considerable time and effort into the assignment, the program does not fulfill any of the above requirements but it does compile.

D- submissions:

The student has invested considerable time and effort into the assignment, the program does not fulfill any of the above requirements and it does not compile.

Other submission requirements

  1. Good coding style and documentation:  They will play a role in determining your final grade for this assignment.  Your grade can be reduced by a letter step or more if your submission was implemented using bad style conventions (e.g., "A" to "A-" for employing poor naming conventions for identifiers, insufficient documentation, the use of global variables other than the cheat mode flag or non-modular design).

  2. Include a README file in your submission:  For this assignment your README file must indicate what grade level you think your assignment should receive (e.g., A, B or C) and the features that you have implemented.  This will allow your marker to quickly determine what he or she must look for and speed up the marking process.

  3. Assignments (source code and the README file) must be electronically submitted via submit.  In addition a paper print out of the source code and README must be handed into the assignment drop box for the lab that you are registered in (located on the second floor of the Math Sciences building).  Electronically submitting the assignment allows your marker to run the code in order to quickly determine what features were implemented.  Providing a paper printout makes it easier for your marker to read and flip through your source code.

  4. A demo is required for this assignment.  You will demonstrate the working features of your assignment to your TA, most likely it will occur in lab the week after this assignment is due.  It is your responsibility to book a demo time during the times allotted by your TA.  It isn't his or her job to chase you down and to set up a time.   If you do not demo your assignment then the highest possible grade that will get for this assignment is a "D".

Sample Executable

You can run a sample executable called "StarTrek" which can be found in Unix in the directory: /home/231/assignments/assignment6

Suggested Approaches to this Assignment:

  1. Start early!  This is your first "tough" assignment.  Although there's not a lot of new concepts that you have to understand and apply for this one, finding the solution to the problem will be a bit trickier.

  2. Take it in small steps.  Get the basic program working before you start working on the additional features.  Make sure it really works by testing it!  

  3. Back up your work!  Once you get your basic program working make a backup copy (e.g., at Unix type 'cp StarTrek.p StarTrek.June9'.  As you complete additional features backup these versions and don't touch the backup and when you start working on more features, modify only the copy.

  4. Do attempt this assignment.  Although it isn't worth a large percentage of your final grade, writing these programs really helps you to truly understand the concepts that you were taught in lecture.

 

  1. The images from this page and the Star Trek concept are © Paramount.
  2. From www.startrek.com