Topic: Solitaire Solver
Directions: Create a game which intelligently plays Solitaire.
There will not simply be an array of cards to choose from, because that would make cheating very easy. There will be arrays of cards, showing only the ones that are facing up. (The ones facing down are invisible to the programmer.)
card_array might contain the card on the top of pile 1. card_array might contain the second card down from the top of pile 2.
So it's: int card_array[pile][card in pile going from top downward]
Piles 0-6 will be the normal solitaire piles. Piles 7-10 will be the ones on the top where you put them last. Pile 11 will be the discard pile, which would show the card just served off the deck. All piles are read from left to right. Cards 0-12 are diamonds, the next 13 are hearts, the next 13 are clubs, and the last 13 are spades. (So, red cards are 0-25, the black cards are 26-51). This is a global variable. (I would've made it local, but that's too much work for something like this.) If a card turns up -1, that means that card does not exist, and you've probably gone to the end of that pile. (If the first card in a pile is -1, that means that pile is empty.)
This function takes a card from the serving pile (I forget the technical name) and places it in the discard pile. You can assume that each time it's only one card this is happening to. The value returned will be either the value of the card returned (cards are valued 0 to 51) or -1 if it has reached the end of the pile. It will automatically reset if it's at the end of the pile.
int move_card(pile number card is in, pile number card is moved to, number of cards moved);
This returns a 1 if successful, and a 0 for failure. Reasons for failure include breaking the rules or incorrect pile numbers.
Any possible functions i missed?
Your (the contestant's) function will be called:
Inside it you will move cards, draw new cards, and basicly interact with the game so that you win. You are encouraged to use all the resources at your disposal to win, but it's impossible to peek. You can count cards that have already gone by, if you want to factor it into your decision.
After deciding the right move the program should call the move function. Then everything is automatically updated and you go through the process again until you win or lose.
It's up to your program to decide whether or not to lose. A winning scenario is easy to spot, but a losing scenario requires that you concede defeat yourself. Return a 0 for a defeat, and a 1 for a win.
efficiency -- use computer resources efficiently
elegance -- make your code neat and understandable. The structure and planning put into your program is key
portability -- how many computers can your code compile across? (especially important, cause i got to link with the code)
Interface -- make your interface user-friendly and idiot-proof
Success rate/Intelligence -- Does this game win more often than normal?
Stability/Garbage Collection -- does your game clean up after itself? (ie: memory leaks?) when will it crash? how stable is it?
Time Limit: For this one i'll be generous and say that all entries need to be in by September 24.
Signed up Contestants: 8 slots left
Signed up Judges: all slots filled
Send all entries to email@example.com or firstname.lastname@example.org
You can also submit your entry at the web site, contests.cprogramming.com
Have fun! To join in just reply to this thread.
Remember, above all, make sure your program works.