Programming Project #4



Ground Rules

1.0 Problem Description

You are to create an program that can play a version of a solitaire card game called "Accordian'' solitaire, the rules for which are as follows:

A standard playing deck is used. Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate neighbor on the left, or matches the third card to the left, it may be moved onto that card. Cards match if they are of the same suit or same rank. After making a move, look to see if it has made additional moves possible. When a card is moved, all the cards in the pile are moved. Gaps between piles should be closed up as soon as they appear by moving all piles on the right of the gap one position to the left. Deal out the whole pack, combining cards towards the left whenever possible. The game is won if the pack is reduced to a single pile.

Situations can arise where more than one play is possible. Where two cards may be moved, you should adopt the strategy of always moving the leftmost card possible. Where a card may be moved either one position to the left or three positions to the left, move it three positions.

Play an interactive version of Accordian Solitaire.


Input data to the program specifies the cards for several games.  Each line of input contains the the cards for a single game, in the order in which they are dealt from the pack.  Each line may contain 1 to 52 cards separated by a single space. The line ends with "00" (double zeroes).  The final line of the input file contains only double zeroes. Cards are represented as a two character code. The first character is the suit and the second character is the rank.


One line of output must be produced for line of input. Each line of output shows the cards remaining after playing a round of the game with the pack of cards as described by the corresponding input line.

Sample Input

C7 D7 H3 H5 00
D2 HK SJ C3 H3 00
H2 H3 H4 H5 HK DK D2 D3 D4 00
C7 C4 D9 ST CT S1 HT S9 C9 CQ D6 H7 S2 H5 S5 D3 DT C2 S4 SK H3 DJ C6 S8 C5 DK C8 SQ C1 H9 S7 D4 CJ S6 D2 D1 S3 D8 D7 DQ HQ HJ HK H4 CK H8 SJ C3 H2 H1 H6 D5 00

Sample Output

D7 H5 
D2 H3 SJ C3
H7 C5 H6

2.0 Constraints

The main function for your program is to be named accordion.c
You must decompose your solution into small functions each of which performs a specific task.  It is recommended that you put the functions in a separate file, though it is not required.

3.0 Testing

It is recommended that you unit test your functions with checkit.

4.0 Grading

application produces correct output for all instructor test cases.
Program design is effectively decomposed into several small well-defined, special-purpose functions
15% Algorithm design uses structured logic for decisions and loops.
15% Coding standards are followed.
5% Clean compile and link (no warnings using the required compiler flags).

Remember, your program will be tested on Unix1.  Code that does not compile will receive a grade of zero.

5.0 Submitting Your Work

You need to submit your source code electronically using the   handin   utility: No late submittals will be accepted! 

  1. You may submit as many source code files as you like, but only one of them may contain a main function.
  2. The file containing the main function must be named accordion.c.
  3. Your files will be compiled with this command:   gcc -c -Wall -ansi -pedantic *.c
  4. Move the necessary file(s) to your Unix1 account using your favorite secure file transfer program.
  5. Log on to Unix1 using your favorite Secure Shell client program.
  6. Change directory (cd) to the directory containing your source file to hand in.  
  7. Be sure to compile and test your code on Unix1 using the required compiler flags ( -Wall -ansi -pedantic) one last time just before turning the files in.
  8. Submit your code using handin:
    handin graderjd Project4  accordion.c  (optional other files)

Accordion Project
Function statement counts (instructor solution)

main - 8

total 77

Easier testing.
Easier debugging.
Opportunities for reuse.