Project 3 — Monte Carlo Solitaire

AssignedSaturday, March 16
Program DueTuesady, April 9thth by 11:59pm
Weight8%
Updates As a point of clarification, the Game class's getSuit(Coordinate) and getRank(Coordinate) methods should return null if no card is present at the specified coordinate. Rank.java, Suit.java

Objectives

Project Description

As an employee of the UMBC Game Company, you have been assigned to the programming team responsible for designing and implementing a 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 played face up, in 5 rows with 5 cards in each row. These cards are called the “tableau.” The player removes pairs of adjacent cards (horizontally, vertically, or diagonally).

When no more pairs can be removed, the tableau must be “consolidated.” Consolidating the tableau will attempt to shift the remaining cards to fill in the holes in the tableau. The tableau will traverse itself row by column looking for any holes. When a hole is found, the tableau will move the next card on the traversal into the hole that needs to be filled. If there is no card in the tableau that can be used to fill that hole, a card must be dealt from the deck and placed into the hole in the tableau. The consolidate operation has completed when the tableau has completed the traversal of itself, or there are no cards left in the deck. To help you visualize the consolidate operation, use the following image of the tableau.

Consolidate Illustration

Online Demo

You can play an online version of the Monte Carlo Solitaire application you will be building below.

Launch

If you have Java installed you should be able to download and run a demo of the app by simply clicking on the button above. If you have any issues running the app that way, try downloading the p3.jar file directly and run the demo with the following command: java -jar p3.jar

Game FAQs

  1. How is the game number chosen and how is it used?

    When the game initially starts, a game number is randomly chosen by the GUI. A new game can be created by either selection a game number at random (Game → New Random Game) or by specifying a specific game (Game → New Game…). The game number is used to initialize the random number generator used to shuffle the cards.

  2. What does the “Control → Hint” menu option do?

    When “Control →Hint” is selected, a pair of cards that may be removed are highlighted (their borders change color). If no pair of cards can be removed, a message indicating no move is available is shown.

    Implementing “Hint” is worth 5 points extra credit.

    Be sure that you set Game's isHintImplemented() method accordingly.

  3. What does the “Help → Monte Carlo Solitaire” menu option do?

    The “Help → Monte Carlo Solitaire” option displays a pop-up window that briefly explains the rules of the game.

  4. What does the “Game → New Random Game” option do?

    The “Game → New Random Game” option abandons the current game, selects a new random game number, seeds a random number generator, and starts the new game.

  5. What does the “Game → New Game…” option do?

    The “Game → New Game…” option abandons the current game, prompts the user for a new game number, seeds the random number generator with that selection, and starts the new game.

  6. What does the “Game → Replay Current Game” option do?

    The “Game → Replay Current Game” option restarts the current game from the beginning.

  7. How do I win the game?

    By removing all the cards from the tableau, hence earning a score of 52.

  8. What's the tableau?

    The cards that are face up in a rectangular arrangement (usually 5 × 5).

  9. How do I remove cards from the tableau?

    Clicking on a card highlights that card by changing its border color. 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.

  10. 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.

  11. What do I do when I can't remove any more cards?

    Push the card to the top-left or select the “Control → Consolidate” button. This 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.

  12. What if there aren't enough cards in the deck to fill the bottom of the tableau when I “consolidate”?

    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.

  13. 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 & Enum Descriptions

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

View all Javadocs

You are not permitted to make any changes to Project3.java, ClickableImage.java, ClickableImageGrid.java, Suit.java, or Rank.java.

However, you are welcome to add additional members/methods (public or private) to the other classes referenced in the Javadocs. Additionally, you are welcome to add additional helper classes as you see fit.

Project Requirements and Specifications

  1. This project will require you to create a new project based on one that we have started to develop. Download p3.zip and use Eclipse's import tool to create a new project from an Existing Project.
  2. 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.
  3. For any given game number from the online demo GUI, your application should duplicate the tableau for that same game number.
  4. 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: A♣, 2♣, …, Q♣, K♣, A♦, 2♦, …, Q♦, K♦, A♥, 2♥, …, Q♥, K♥, A♠, 2♠, …, Q♠, K♠.
  5. The algorithm below, which shuffles an array of items, must be adapted and implemented to shuffle the cards to start a new game of solitaire.

    1. A[0], A[1], …, A[N-1] is an array of items
    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.util library. Note: Read the description of the nextInt(int n) 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 you create part of package “proj3”.

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 from the provided zipfile. 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 cmsc202 proj3 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 cmsc202 proj3

See the Project Submission page for detailed instructions.

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!