Project #7

CMSC 131

Due:  Monday,  May 10, 11:00PM

Object-Oriented Programming I

Type of Project: Closed

Spring 2010


5/2: If you get an UnsupportedClassVersionError when building your Tron project, then you need to replace the tron.jar file in your project's library directory with this one. (The problem was that the tron.jar file distributed with the project was built with Java 1.6, and you are running Java 1.5).

TRON EXAMPLE GAME:

 

Objective

This project will give you practice in further use of two-dimensional arrays, will give you experience using collections (ArrayList), and give you further experience creating programs that reflect your general thinking about problem solving. As with project 6, this will offer a competitive environment for you to test your skills.

 

Overview

The finished project will be an implementation of the gameplay logic of Tron, a simulation based on the original and upcoming movie. You will write code for your simulation as described below and submit as usual to the submit server.  As with project 6, as soon as your submission passes all of the release tests, it will be entered in an automated competition where your solution is played against every other student's solution.  There is a public leaderboard that shows how each person is doing and also shows the complete history of every game.  You are encouraged to submit early so you can compete against other students, analyze why your code wins or loses, and then improve and resubmit your code. The tournament engine runs 24/7, taking the latest successfully submitted projects and running a new tournament every 10 minutes.

The main leaderboard shows the results of only the class students, but as an extra motivation, there is an option to include the TA solutions.  So, see how well your program can do.  Compete early and often.  Study how your solution plays in response to other students (and TAs) solutions and see if you can come up with a better algorithm.  You will not be graded on your ranking in the competition, but you will definitely get bragging rights.

Note that when you define your solution, you also have a mechanism to define the name that your solution will be posted under.  You are free to use your real name, your class account, or an anonymous name of your choosing - so you aren't obligated to share your ranking with others.  However, we will know who is who, so you may not use any name that is offensive or that implies that you are someone else.

Look at the Leaderboard to see current results.

Game Structure

As with the previous games, the simulation is structured around game state, which is simply the state of the board of the game at any given time. The Tron game state consists of a two-dimensional board where two opponents race on the board, the locations of the "head' of each player, and a collection of obstacles that the players must avoid.  As each player moves, they leave a trail, and your job is to race as long possible without bumping into the edge of the board, a trail left by you or your opponent, or an obstacle.  Thus, the rules for this game are quite simple, but the strategy for playing well is difficult.

With this project, you have been provided with more code related to the game state so that you can concentrate on a strategy for winning rather than on the underlying mechanics of the system.  In particular, you are provided with everything except for the two methods that generate strings representing the state.  The essence of the solution for each turn is to simply pick one of four directions to move.  Of course, you must pick directions that are legal and that are good.  And you must implement that movement by updating the state appropriately. The definition of a legal move is one that:

If there are no legal moves available to you, then you should just leave the state unmodified and you lose. The winner is simply the player that lives the longest.

Project Details

You must write the TronStateUtil and TronSoln classes in the "<studentacct>.tron" package according to the following requirements.

Important notes for all code that you write for this project:

TronStateUtil Class

This class provides two methods used by the TronState class.  You must write the dump() and toString() methods that are defined in the JavaDocs.

Note that that the state contains three components (the board, the heads, and the obstacles).  The board contains *only* an indication of where players have been.  It does not contain the head position of the players, nor does it contain the obstacles.  Your program will have to use all three elements of the state to create a correct solution.

TronSoln Class

This class represents the solution to the Tron simulation. As described previously, your primary goal is to implement the game logic to play a legal game.  It is up to you to figure how how to play well. Note that in this project you are not obligated to beat a random player.

To make a move, you must update the state to reflect your move.  This means you must change the board by indicating where your player moved, and you must also update your player's head to indicate where the head of your player is at this point. Unlike the previous project, you are not allowed to modify the board directly, instead you must use the provided setCell() and setHead() methods. So, to move to the new position (row, col), you should execute these two lines of code:

    Cell pt = new Cell(row, col);
   state.setCell(row, col, playerNum);
   state.setHead(playerNum, pt);

This class provides a solution to the Tron game.  It must meet the following requirements.

 

JUnit Tests

You are required to write a series of JUnit tests to test all the methods that you write. You do not have to write unit tests for your TronSoln.move() method, but you will probably implement move() by writing smaller methods that do specific tasks (such as determining what the possible moves are), and you can write tests for those smaller methods.  Create a class called "StudentTests" in the default package (for each of the two games), and put your tests into that class.   If the tests are not located in this file, your submission will fail.

Each time you write a significant method for your class, you should write a series of JUnit tests (in the StudentTests.java file) that check to ensure that the method is working as it should.  If you come to office hours for help debugging this project, the first thing we are likely to ask you is:  "Show me a JUnit test that demonstrates the problem you are having."

 

Documentation

All code you write must be well documented:

Requirements

As with all programming assignments:

 

Grading

Your grade will be computed as follows: