Design and development of significantly sized software using top-down design and bottom-up implementation. Dynamically allocated data, object-oriented programming, architecture of memory, basics of language translation, and basics of algorithm analysis. Development of simple graphical user interfaces. Prerequisite: CS 110 (grade of C or better).

Project 3 - Play Chutes and Ladders with the Computer - (100 points)



Due date: Part 1 - 3/10/2016 at 11:59pm

Due date: Part 2 - 3/12/2016 at 11:59pm

Objectives



  • Learn about array manipulation
  • Gain practice with algorithmic thinking
  • Familiarize yourself with dependencies within classes

Part 1 - Setup the Game



For this assignment, you will practice algorithmic thinking and array manipulation by implementing a Chutes and Ladders program. Your program will allow a user to play chutes and ladders against the computer. For this part of the program you will need the following:

  • Board class - This class contains the configuration for the board and its supporting methods. It will contain the following:

    • Array of Strings (positions) whose index will be the position on the board. It will also hold the Player/Computer location, if they are on a specific position on the board.
    • A chutes and ladders configuration array (configuration) that will serve as a lookup table to move the player/computer to a new location if a chute or ladder is at that position on the board.
    • A way to store the current index of the player and the current index of the computer
    • A constant integer variable that contains the size of the board
    • A constructor that takes in the name of the chutes and ladders configuration file. Initialize the positions array. Set the player and the computer to index 0 to get started.
    • public int getBoardSize() - returns the size of the board. Note: I would highly recommend testing your program first on a board of 20 elements and then slowly increasing the board size to 100 by the end of the assignment.
    • public void printBoard() - Prints the current configuration of the board. If a position has the Player or Computer or both on it, then display a P/C/P,C to indicate where the player and the computer is at that point.
    • public int getPlayerPosition() - returns the current position of the player
    • public int getComputerPosition() - returns the current position of the computer
    • public void setPlayerPosition(int dice) - Set the player to the new position on the board by adding the player's current position to the value obtained by rolling the dice. If the player's new position is greater than the size of the board, then the display a message informing the user that the player wins and exit the program using System.exit(0). Make sure to reset the player's previous position to an empty string after you've updated the player's new position.
    • public void setComputerPosition(int dice) - Set the computer to the new position on the board by adding the computer's current position to the value obtained by rolling the dice. If the computer's new position is greater than the size of the board, then the display a message informing the user that the computer wins and exit the program using System.exit(0). Make sure to reset the computer's previous position to an empty string after you've updated the computer's new position.
  • Game class - This class contains the main() and creates an instance of the board class. It keeps track of the player's and computer's current position and keep's rolling the dice (to get a number between 1 and 6) till the position of the player and the computer is less than the size of the board. Make sure to display the result of rolling the dice for the player and the result of rolling the dice of the computer. Display the updated positions of the player and the computer as well as the configuration of the board after every round. Note: This will help immensely with debugging.

Part 2 - Setup the Chutes and Ladders



For this part of the program, you will need to read in a configuration file that contains two numbers per line. The file can be as follows (for a board that has 20 positions):
5,12,
17,10,
14,19,
18,7,

  • For this part, you need to make changes to the constructor of the Board class.
  • Read in the specified file and populate the configuration array such that the first value is the index of the array and the second value is the value at that location in the array. For the first line, it will look like configuration[5] = 12; in memory. Naturally, hard coding the configuration file is not a solution since we will test your program with a board size of 100 and different configuration files.
The first number on a line contains the index of a position and the second index contains the destination of the player/computer. For example, 5,12 is a ladder such that if the player's position falls on 5 after rolling the dice, then the player's new position is 12 and needs to be updated accordingly. If the computer's position after rolling the dice is 17 then according to the line 17,10, the computer's new position is now 10 and the computer went down a chute.

  • Make sure to inform the user whenever a player/computer takes a chute/ladder and display the updated board for information as well as for debugging.
  • For this part, I recommend making changes to the public void setPlayerPosition(int dice) and the public void setPlayerPosition(int dice) methods so that you can lookup the player/computer's position and decide whether a chute/ladder exists at that point.

Testing your program



  • Start small and test your program on Part 1 to make sure that it works on a board of size 20.
  • Make sure the player/computer wins according to the rules of the game.
  • Grow the size of your board to 40/50 and then test it again.
  • Tweak your printBoard() method, so that you can see the entire board in one screen even with a board size of 100.
  • Test your program on a board size of 100 elements.
  • For Part 2, go back to testing your program on a board size of 20 elements first and make sure that the chutes and ladders are working correctly.
  • Similar to previous steps, work up slowly towards higher board sizes before testing on a board size of 100.
  • This is NOT supposed to be an interactive program. Do not take any input from the user. You are supposed to run the program and let it run till the program displays a winner and quits.

Submitting the assignment



  • Submit the java files in a directory called project3 with a README file
  • You can resubmit the assignment as many times as you want. It will upload a new copy of the files to the SVN repository. We will only grade the one that is closest to 11:59pm on the due date.