CMSC 202 Project 2

Monte Carlo Solitaire

Assigned Wednesday, October 7
Program Due Wednesday, October 21, 10:00am
Weight 7%
Updates 12 October: Two more files have been placed in Ms. Mitchell's pub directory that are necessary to copy into your proj2 package: ClickableImage.java and ClicableImageGrid.java. My oversight. (Ms. M)
11 October: You may receive +5 extra credit points if you correctly implement the Hint button (see info in red below).
11 October: Project2.java (the GUI class is now available in Ms. Mitchell's pub directory at /afs/umbc.edu/users/s/m/smitchel/pub/202/Proj2
11 October: The Game class interface specification can be found here.

Objectives


Project Description

As an employee of the B, F, & M Game Company, you have been assigned to the programming team responsible for designing and implementing an on-line version of "Monte Carlo Solitaire." Monte Carlo Solitaire is played with a standard deck of 52 playing cards (4 suits and 13 ranks). Initially, 25 cards are laid out in 5 rows with 5 cards in each row. These cards are called the "tableau." The player removes pairs of touching cards (horizontally, vertically, or diagonally). When no more pairs can be removed, the tableau is "consolidated." The cards that remain in the tableau are moved left, then up, to fill in the spaces left by the cards which were removed. New cards are dealt from the deck to once again complete the 5 x 5 tableau or until there are no more cards. The player wins the game by removing all the cards from the tableau.

You can play a competitor's version of Monte Carlo Solitaire here. Our version of the game is, of course, far superior, since it includes more functionality, such as help. Also note that the rules for our competitor's game are slightly different than ours. Here is a sample screenshot of our GUI.

Game FAQ
  1. How is the game number chosen and how is it used?
    The game number is chosen by the GUI. The first game played is #12345. The game number is used to initialize the random number generator used to shuffle the cards.
  2. What does the "Hint" button do?
    When the "Hint" is pushed, a pair of cards that may be removed are highlighted (their borders turn red). If no pair of cards can be removed, a beep is sounded. (+5 points extra credit if implemented)
  3. What does the "Help" button do?
    The "Help" button displays a pop-up window that briefly explains the rules of the game.
  4. What does the "New Deal" button do?
    The "New Deal" button abandons the current game and starts a new game.
  5. What does the "Replay" button do?
    The "Replay" button restarts the current game from the beginning.
  6. How do I win the game?
    By removing all the cards from the tableau, hence earning a score of 52.
  7. What's the tableau?
    The cards that are face up in a rectangular arrangement (usually 5 x 5).
  8. How do I remove cards from the tableau?
    Clicking on a card highlights that card by changing its border to red. If the next card clicked is touching the first card and is of the same rank, the cards are removed. If the second card is not touching the first card or is not of the same rank, a beep is sounded. Suits are not relevant when choosing cards to remove.
  9. When are two cards touching?
    Two cards are touching if they are next to each other horizontally, vertically, or diagonally. Cards at the top and bottom of a column, or the ends of a row, or the opposite corners of the diagonal are NOT considered touching. That is, the columns, rows, and diagonal do not wrap. Note that this is different from the competitor's implementation in some ways.
  10. What do I do when I can't remove any more cards?
    Push the "Consolidate" button. This button always moves all cards in the tableau left and up towards the top of the tableau. If there are any cards left in the deck, then this button also deals cards from the deck to refill the bottom of the tableau.
  11. What if there aren't enough cards in the deck to fill the bottom of the tableau when I push the "Consolidate" button?
    If there are too few cards in the deck to complete the tableau, the remaining cards are dealt to complete as much of the tableau as possible.
  12. How does my score change?
    One point is awarded for each card removed from the tableau.

Project Policy

This project is considered an OPEN project. Please review the open project policy on the course website.


Class Descriptions

Our application consists of many classes. Some of the classes have already been written by other team members. Some of the classes will be written by you. Some classes must support a specific API, and still others may be designed and implemented as you see fit.

Project2 Class
Project2.java, which contains the GUI framework and the project's main, are being written by someone else. The GUI code in Project2.java calls methods from the Game class that you will design and implement. When complete, you will be given the Project2.java file and other GUI framework files on which it depends to complete your program. When available, copy Project2.java and all other .java files from Ms. Mitchell's public directory. To integrate these files into your project, see the Importing Files into Eclipse resource page. Do not submit Project2.java.

Suit Class
Suit.java has been written and can be copied from Ms. Mitchell's public directory. This class defines Suit objects used to identify a card. For example, Suit.HEARTS is used to represent the suit hearts. This class is provided so that there is no possible discrepancy among all classes that refer to a card's suit. The four suits in a standard 52-card deck are Suit.HEARTS, Suit.SPADES, Suit.DIAMONDS, and Suit.CLUBS. Do not submit Suit.java. Documentation for Suit.java is provided in the file itself and in the Suit API document.

Rank Class
Rank.java has been written and may be copied from Ms. Mitchell's public directory. This class defines Rank objects used to identify a card. For example, Rank.TWO is used to represent a card with a rank of two. This class is provided so that there is no possible discrepancy among all classes that refer to a card's rank. The ranks of the cards in a standard 52-card deck are Rank.ACE, Rank.TWO, Rank.THREE, ... Rank.JACK, Rank.QUEEN, and Rank.KING. Do not submit Rank.java. Documentation for Rank.java is provided in the file itself and in the Rank API document.

Game Class
Game.java must be written by you. This class contains data and methods used by the Project2 class. A description of the Game class API will be provided in Javadoc format soon, but we are first going to discuss this API in class during the Project 2 Design session . Note that your class must follow the released API, or Project2.java will not compile.

Coordinates Class
Coordinates.java must be written by you. This class encapsulates the row and column coordinates of a card in the 5 x 5 tableau. This class is also used by Project2.java. A description of the Coordinates class API is provided in Javadoc format.

Other Classes
Design and implement any other class(es) that you feel is(are) necessary to complete a good object-oriented implementation of this project. Yes, there should be some other class(es).


Project Requirements and Specifications
  1. Ms. Mitchell's public directory for this project is /afs/umbc.edu/users/s/m/smitchel/pub/202/Proj2/.
  2. A directory named cards that contains card images to be used for this project can be found in Ms. Mitchell's public directory. Copy this directory into your Eclipse project so that the cards directory is at the same level as the src directory. The cards directory is also available in tar and zip formats.
  3. You must write main in the Coordinates class, the Game class, and any class you design and implement as a means of unit testing. As discussed in class, each main should instantiate an object and invoke all public methods defined for the class, printing the results to System.out.
  4. The screenshot of our GUI shows the tableau for game #12345. Your application should duplicate this tableau when the first game is played.
  5. The algorithm below, which shuffles an array of integers, must be adapted and implemented to shuffle the cards to start a new game of solitaire. This algorithm is known as the Fisher-Yates algorithm, was first designed for computers by Richard Durstenfeld, and popularized by Donald Knuth.
    1. A[0], A[1]... A[n-1] is an array of integers
    2. Let N = n-1
    3. Pick a random index, k, between 0 and N (inclusive).
    4. Swap the values of A[k] and A[N].
    5. Decrease N by one.
    6. Repeat from step (c) until N is less than 1.
    To choose a random index (step c), use the nextInt method of the Random class found in the Java library. (Note: Read the description of the nextInt method carefully!)
  6. Per the course standards, all class comments must contain the class invariant and all method comments must include pre- and post-conditions.
  7. Make all .java files part of package "proj2".
  8. In order to duplicate game #12345 as required above, it is necessary that the deck of cards be initialized appropriately before shuffling. Initialize the deck of cards in the order Ac, 2c, 3c, ..., Qc, Kc, Ad, 2d, ..., Qd, Kd, Ah, 2h, ..., Qh, Kh, As, 2s, ..., Qs, Ks.


Hints and Tips

Grading
See the course website for a description of how your project will be graded.
Project Submission
  1. submit Game.java, Coordinates.java and the .java files for any class(es) you design and implement.
  2. DO NOT submit any .java files you copy from Ms. Mitchell's public directory. These files should not be changed by you and so need not be submitted. If you submit these files, they will be removed from your submittal directory.
  3. submitls cs202 Proj2 to verify that your files are in your submittal directory.
The order in which the files are submitted doesn't matter. You need not submit all files at the same time. You may resubmit your files as often as you like, but only the last submittal will be graded and will be used to determine if your project is late. For more information, see the projects page on the course website.

You can check to see what files you have submitted by typing

submitls cs202 Proj2 More complete documentation for submit and related commands can be found here.

Remember -- if you make any change to your program, no matter how insignificant it may seem, you should recompile and retest your program before submitting it. Even the smallest typo can cause compiler errors and a reduction in your grade.

Avoid unpleasant surprises!