Overview

You are to write a program that simulates playing the solitaire card game Clock. We provide several sites at the end of this document that describe and demonstrate the rules; we suggest you familiarize yourself with the game first. Heres how we want you to implement the simulation.

Part 1 - Required Classes

Create a Card class that can represent each of the 52 playing cards: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King in each of the four suits: Spades, Hearts, Diamonds, and Clubs.

Implement the following methods:

  • constructors
  • getSuit()
  • getValue()
  • String toString()

Create a Deck class that represents a standard deck of 52 playing cards.

Implement the following methods:

  • constructors
  • void shuffle(): randomly interchanges cards in the deck to simulate shuffling
  • Card dealCard()
  • int cardsLeft()
  • String toString(): iterate through your deck array, printing all the cards, in a way thats convenient to check what cards are there; we think itll be best to print all the cards on one line (or print them on four lines, if you want to get fancy); for cards that have been dealt, either dont print them, or print them separately, labeled as dealt

Create a Pile class that contains no more than five cards some face down, and some face up.

Implement the following methods:

  • constructors
  • void addCardFaceDown( Card card)
  • Card removeCard() - removes and returns the top face down card (null if there are none)
  • int getNumberOfFaceDown()
  • void addCardFaceUp( Card card)
  • int getNumberOfFaceUp()
  • String toString() - print the cards in the Pile; print the contents of a pile on one or two lines; label the portion of the pile thats face up versus face down

Part 2 - The Clock Solitaire Game

Implement the Clock Solitaire Game simulation, with all the following capabilities. We strongly suggest you dont ignore handling command line arguments, as this feature is simply to implement, and will be a great help in your debugging process, and in our grading. Name your primary class -- the one with the main() method -- ClockSolitaire.

Command-Line Arguments

Your program will accept two command line arguments. (These arguments are optional, and your program will use the default values if the argument(s) are not specified. And, implementing handling of command line arguments is not optional.)

  • Print level - one of the following three values:
    • verbose
    • normal (the default)
    • silent
  • Number of games to play (default: 1)

Setup Tasks

  • create thirteen Piles
    • these should be stored in an array of Piles (rather than thirteen discrete variables)
  • create and shuffle a Deck of Cards
  • deal out the deck to populate (initialize) the thirteen Piles with four face-down cards each
    • You may deal one card for each of the thirteen Piles, and then a second card, and so on
    • or, you may deal four cards to fill the first Pile, four for the second Pile, and so on
  • print the thirteen Piles -- the game board (this will mainly uses Pile.toString() ), if the print level is not silent; label each pile with its clock position; for simplicity, you can print one pile per line (you can get more creative, if you like)
  • print the score: the number of Piles with at least one face-down card, if the print level is not silent; note a game is won when the score is zero
    • this will be 13 at the beginning of each game

Playing the Game

  • remove (top, face-down) card from Pile 13, the Kings Pile
  • add it, face-up, to the (bottom of the) correct Pile
  • if the print level is verbose, print the game board -- the thirteen Piles -- as above
    • also, keep track of and print the step number, a counter that you increment each time you remove-and-add a card
  • remove (top, face-down) card from that same Pile
    • one needs to check that there are face-down cards remaining
    • if there are no face-down cards remaining, the game is over, if youre on Pile 13
    • (if there are no face-down cards remaining, and youre not on Pile 13, then theres an error)
  • repeat this process by going to step 2

When Each Game is Done

  • print the thirteen Piles -- the game board (as above), if the print level is not silent
  • print the score: the number of Piles with at least one face-down card, if the print level is not silent
    • a score of zero is a win; note this is rare
  • increment a counter in a Scores array for the number of Piles with at least one face-down card
  • repeat, from the top (the Setup), according to how many games to play, as specified in the command-line arguments

When Youve Completed Playing the Required Number of Games

  • print the number of games played
  • print the Scores array, along with percentages, as follows; this will be 14 lines, with both the number and percentage of games that resulted in each score
  • (print this for all print levels, including silent)

References: Rules of the Game

Here are some sites that describe the rules of Clock, and one that allows you to play it online:

  • https://www.thespruce.com/clock-solitaire-rules-412468
  • https://en.wikipedia.org/wiki/Clock_Patience
  • https://youtu.be/6AEJEf8L95g
  • http://cardgameheaven.com/single-player-games/clock.html
  • http://www.novelgames.com/en/clocksolitaire/ (this site lets you play online)
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.