User Tools

Site Tools


user:nbrimme1:portfolio:dataprojectf

Data Structures Project 7: Card Game "FreeCell", "Forty Thieves", "Eight Off", or "Baker's Game"

A project for COURSENAME by YOUR NAME OR GROUPMEMBER NAMES during the SEMESTER YEAR.

This project was begun on DATE and is anticipated to take X AMOUNT OF TIME. (Upon completion you can correct this with the actual length).

This project was supposed to be a final project, but Matt changed his mind…not sure if that's good or bad.

Objectives

State the purpose of this project. What is the point of this project? What do we hope to accomplish by undertaking it?

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

  • resource1
  • resource2
  • resource3
  • experience1
  • experience2
  • etc.

Background

State the idea or purpose of the project. What are you attempting to pursue?

Upon approval, you'll want to fill this section out with more detailed background information. DO NOT JUST PROVIDE A LINK.

Providing any links to original source material, such as from a project page, is a good idea.

You'll want to give a general overview of what is going to be accomplished (for example, if your project is about installing a web server, do a little write-up on web servers. What is it, why do we need one, how does it work, etc.)

Scope

Give a general overview of your anticipated implementation of the project. Address any areas where you are making upfront assumptions or curtailing potential detail. State the focus you will be taking in implementation.

Attributes

State and justify the attributes you'd like to receive upon successful approval and completion of this project.

  • attribute1: why you feel your pursuit of this project will gain you this attribute
  • attribute2: why you feel your pursuit of this project will gain you this attribute
  • etc…

Procedure

The actual steps taken to accomplish the project. Include images, code snippets, command-line excerpts; whatever is useful for intuitively communicating important information for accomplishing the project.

The first step was to become familiar with the rules and vocabulary for the 4 card games. Not only do I need to memorize C vocabulary, now I need to learn some Solitaire vocabulary :-X (A glossary of solitaire terms can be found here):

1. "FreeCell":

  • One standard deck of cards is used, 52 total cards, 4 suits (Club, Heart, Diamond, and Spade, each with Ace through King), 2 colors (Black and Red).
  • Rules:
    • Construction and layout:
      • There are 4 open “cells” and 4 open “foundations” above the “cascades”.
      • Cards are dealt into 8 “cascades”, 4 of which comprise 7 cards and 4 of which comprise have 6 cards.
    • Building during play:
      • The top card of each “cascade” begins a “tableau”.
      • “Tableaus” must be built down by alternating colors.
      • “Foundations” are built up by suit.
    • Moves:
      • Any “cell” card or top card of any “cascade” may be moved to build on a “tableau”, or moved to an empty “cell”, an empty “cascade”, or its “foundation”.
      • Complete or partial “tableaus” may be moved to build on existing “tableaus”, or moved to empty “cascades”, by recursively placing and removing cards through intermediate locations. Computer implementations will often show this motion.
    • Victory:
      • The game is won after all cards are moved to their “foundation” piles. Note: It is possible (and easy) to deal examples that result in unsolvable games.

2. "Forty Thieves":

  • Two standard decks of cards are used, 104 total cards, 8 suits (2 Clubs, 2 Hearts, 2 Diamonds, and 2 Spades, each with Ace through King), 4 colors (2 Blacks and 2 Reds).
  • Rules:
    • Deal ten “tableau” piles of 4 cards each, all face up and all visible.
    • Leave space for 8 “foundation” piles above the “tableau” piles.
    • You may only move the top card from any “tableau”. You may place any one card in an empty “tableau” space.
    • For every empty “tableau” you may move one card at once from one “tableau” to another, as a short cut, as long as all cards you move are built down by suit.
    • The “tableaus” are built down by suit.
    • The “foundations” are built up by suit, from ace to king.
    • You may deal one card at a time from the “stock” to the “waste”.
    • You may use the top card from the “waste”.
    • You may only go through the “stock” once.
    • The object of the game is to move all the cards to the “foundations”.

3. "Eight Off":

  • One standard deck of cards is used, 52 total cards, 4 suits (Club, Heart, Diamond, and Spade, each with Ace through King), 2 colors (Black and Red).
  • Rules:
    • The cards are dealt, face up, into 8 columns (or “piles”) of 6 cards each. These 8 columns make up the “tableau”.
    • The remaining 4 cards go into the first 4 “cells” at the beginning of the game, there are a total of 8 “cells”.
    • These “cells” can be used to temporarily store any available card from the table (4 of the cells are filled at the beginning of the game).
    • There are also 4 slots that represent the 4 “foundations”. These are meant to be built up in suit from Ace to King. That is, each foundation begins with the Ace of one suit, followed by the 2 of the same suit, followed by the 3 of the same suit, and so forth, until all the cards through the King have been placed on the “foundation”.
    • The 8 “tableau” piles are where most of the game play actually occurs. The cards are all face up, and are built down, traditionally by suit.
    • Technically, the cards can only move between columns one at a time. However, the presence of a free cell essentially increases the number of cards that can be moved (if there are three open cells, four cards can actually be moved at once; one for each cell, and the one that can always be moved).
    • If a column is emptied, most rules allow for one to place any card in the empty space, regardless of suit or rank (as long as it follows the other restrictions on moving cards).

4. "Baker's Game":

  • One standard deck of cards is used, 52 total cards, 4 suits (Club, Heart, Diamond, and Spade, each with Ace through King), 2 colors (Black and Red).
  • Rules:
    • Construction and layout:
      • There are four open “cells” and four open “foundations”.
      • The entire deck is dealt out left to right into 8 “cascades”, 4 of which have 7 cards and 4 of which have 6.
    • Building during play:
      • The top card of each cascade begins a “tableau”.
      • “Tableaus” must be built down by the same suit.
      • “Foundations” are built up by suit.
    • Moves:
      • Any “cell” card or top card of any “cascade” may be moved to build on a “tableau”, or moved to an empty “cell”, an empty “cascade”, or its “foundation”.
      • Complete or partial “tableaus” may be moved to build on existing “tableaus”, or moved to empty “cascades”, by recursively placing and removing cards through intermediate locations. Computer implementations often show this motion.
    • Victory: The game is won after all cards are moved in ascending order by suit to their “foundation” piles.

The next step is picking a game to actually code. My initial choice is “FreeCell” as it seems the easiest to code. Before you play a card game, you first need a deck. Since “FreeCell” uses only one standard deck, there is only a total of 52 cards used:

Black ♣ Red ♦ Red ♥ Black ♠
A♣ A♦ A♥ A♠
02♣ 02♦ 02♥ 02♠
03♣ 03♦ 03♥ 03♠
04♣ 04♦ 04♥ 04♠
05♣ 05♦ 05♥ 05♠
06♣ 06♦ 06♥ 06♠
07♣ 07♦ 07♥ 07♠
08♣ 08♦ 08♥ 08♠
09♣ 09♦ 09♥ 09♠
10♣ 10♦ 10♥ 10♠
J♣ J♦ J♥ J♠
Q♣ Q♦ Q♥ Q♠
K♣ K♦ K♥ K♠

To “shuffle” the deck, first load the suite into a Doubly Linked List. Then use the rand() C function to pick a random node. The node is pushed onto the deck stack and removed from the list (Black ♣ will be nodes 1 - 13, Red ♦ will be nodes 14 - 26, Red ♥ will be nodes 27 - 39, Black ♠ will be nodes 40 - 52). This process is repeated until the Doubly Linked List is empty then the entire deck can be dealt.

I MIGHT (time permitting) try to implement an “easter egg”. In the HIGHLY UNLIKELY (but possible) event that the card combination in the 4 foundations is '8♠ A♣ A♠ 8♣' (the "Dead Man's Hand" in Poker); the program will exit and print the message “BANG! You're Dead. You got the Dead Man's Hand.”.

Code

/*
 * hello.c - A sample "Hello, World!" program
 * 
 * written by NAME for COURSE on DATE
 *
 * compile with:
 *   gcc -o hello hello.c
 *
 * execute with:
 *   ./hello
 */
 
#include <stdio.h>
 
int main()
{
    printf("Hello, World!\n");    // Output message to STDOUT
    return(0);
}

Execution

Again, if there is associated code with the project, and you haven't already indicated how to run it, provide a sample run of your code:

lab46:~/$ ./helloworld
Hello, World!
lab46:~/$ 

Reflection

Comments/thoughts generated through performing the project, observations made, analysis rendered, conclusions wrought. What did you learn from doing this project?

One thing I learned was that there are unsolvable games for FreeCell. Another idea that I had was writing a game of chess (or Suicide Chess) for the next semester instead of a FreeCell game.

References

In performing this project, the following resources were referenced:

  • Google was of course used for this project:
    • A way to display the color, suit, and number; to make shiz all pretty:
          /* Set the background and text color to look like a playing card:
          Background will be white, cards red and black, and a "reset" to
          remove the colors. */
          #define RST  "\033[0m"   /* Reset the color */
          #define WHT  "\033[37m"  /* White */
          #define BLK  "\033[30m"  /* Black */
          #define RED  "\033[31m"  /* Red */
       
          /* Display Unicode symbols for suits. 'wchar_t' prints a wide character;
          required to display Unicode Symbols. */
          wchar_t cardSuits[] = L"♣♦♥♠", cardNums[] = L"A23456789TJQK";
       
          // Change the background to WHT.
          // Not sure how I can do this yet.
       
          // Print the BLACK "card" then "reset" the color to print RED.
          printf(BLK "BLK card\n" RESET);
          printf(RED "RED card.\n" RESET);
    • FreeCell solutions: Has the solutions (with statistics and videos) to every game of Windows FreeCell. The “Windows FreeCell” has slightly different rules and the games are numbered. Windows 95 had only 32,000 card deals, Windows XP has 1,000,000 card deals. It also contains card deals that result in unsolvable games:
      • Out of the 32,000 games, all are solvable except for game #11982.
      • Out of the 1,000,000 games, 8 are unsolvable:
        • #11,982 (from the original 32,000)
        • #146,692
        • #186,216
        • #455,889
        • #495,505
        • #512,118
        • #517,776
        • #781,948.
  • Wikipedia: Used to gather general information about all four games (The number of decks used, the rules of each game, the card layouts, winning conditions, etc.). All I know is all four games are single player (Solitaire) games; I have never played any of them myself 8-O:

Back to my Portfolio
Back to my Opus

user/nbrimme1/portfolio/dataprojectf.txt · Last modified: 2013/12/10 04:19 by nbrimme1