View Single Post
Old 24-07-2006, 05:49 PM   #52
guesst
Abandonia Homie
 
guesst's Avatar

 
Join Date: May 2005
Location: Aurora, United States
Posts: 606
Default

<div align="center">Acey Deucy</div>
Silly game, fun game. This is a game that you could play yourself with a deck of cards and a pile of M&Ms. The game is played by dealing two cards and choosing whether the next card delt will be between the first two. If the third card is between the first two you win 15 points. If not you only lose 10. If you don't like your odds and decide to forfit looking at the third card you automaticly lose 5. But like most card games this game is cruel, for while it seems like the scoring is to your advantage you will more often than not find yourself in the hole and struggling to climb out.

Code:
/* Acey Duecy 
 * by Joseph Larson 
 * Inspired by a BASIC game by Bill Palmby 
/* as found in 'BASIC Computer Games' edited by David H. Ahl (c) 1978 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>

#define GAIN 15
#define LOSS 10
#define FORFIT 5
#define START 100
#define WIN 200
#define LOSE 0

int score = START;

void intro(void) {
**printf("\nAcey Duecy\n""----------\n"
**"Acey Ducey is played by having the computer deal out two cards. The\n"
**"player then decides on whether the next card chosen will be between the\n"
**"first two dealt, Aces high.\n\n"
**"You start out with %d points. If the third card is between the first to\n"
**"you gain %d points. If not you lose %d points. If you decide not to see\n"
**"the third card you'll automaticly lose %d points\n\n"
**"You win the game if you can get to %d points. But if your points drop\n"
**"below %d it is game over for you.\n\n",
** START, GAIN, LOSS, FORFIT, WIN, LOSE);
**srand(time(NULL));
}

void showcard(int c) {
**if (c <= 10) printf("%d", c);
**else switch (c) {
****case 11 : printf("Jack"); break;
****case 12 : printf("Queen"); break;
****case 13 : printf("King"); break;
****case 14 : printf("Ace");
**}
}

void playhand(void) {
**int card1,card2,card3;
**char yn[50];

**printf("Here are your first two cards:\n\n\t");
**card1 = rand() % 13 + 2;
**do {
****card2 = rand() % 13 + 2;
**} while (card1 == card2);
**showcard(card1);
**printf("\t");
**showcard(card2);
**printf("\n\n");
**if (abs(card1-card2) == 1) {
****printf("Oh, tough luck. There's no card between those two.\n");
****printf("\nSorry. You lose %d points", LOSS);
****score -= LOSS;
**} else {
****printf ("Do want to see the third card? ");
****do {
******printf ("(y\\n) ");
******scanf ("%s",yn);
****} while (tolower(yn[0]) != 'y' && tolower(yn[0]) != 'n');
****if (tolower(yn[0]) == 'y') {
******printf("\nHere is the third card\n\n\t");
******do card3 = rand() % 13 + 2;
******while ((card3 == card1) || (card3 == card2));
******showcard(card3);
******if (((card1 < card3) && (card3 < card2)) 
******|| ((card2 < card3) && (card3 < card1))) {
********printf("\n\nCongratulations. You win.\n");
********score += GAIN;
******} else {
********printf("\n\nSorry. You lose %d points", LOSS);
********score -= LOSS;
******}
****} else {
******printf ("Nothing ventured, nothing gained, %d points lost.\n", FORFIT); 
******score-= FORFIT;
****}
**}
**printf("\nScore : %d.\n", score);
}

int playagain(void) {
**char input;

**if (score >= WIN || score <= LOSE) return 0;
**printf("\nDo you wish to continue? (y\\n) ");
**while (!isalnum (input = getchar()));
**if (tolower (input) != 'n') return 1;
**else return 0;
}

int main(void) {
**intro();
**do playhand();
**while (playagain());
**if (score >= WIN) printf ("Congratulation! You WIN!\n");
**if (score <= LOSE) printf ("Sorry, try again!\n");
**printf ("Thanks for playing!\n");
**exit (0);
}
In the original BASIC game it was a gambleing game. This was the first BASIC game I converted over (since it was the first in the book) and I originally had it that way, but a little while in I decided that I didn't want gambling or shooting games in Cymon's Games, so I retrofitted the program to be point based and not include the betting aspect. To tell the truth, aspects of the game were only just adjusted moments before posting, but rest assure the game was checked before posting.

That's how I found out that VC++ makes executables that are more than 10x the size of the same code compiled in DevC++. Yet another reason to not love M$.

This is not a true dealing alogrythm. Instead, a number between 1 and 13 is just picked out of the air, and as long as it's not the same as any of the numbers picked in that hand before it, it's valid and thrown into the game. Clever programers could adjust the game so that it's a more acurate dealing simulation that reshuffles after a certian number of hands or a certian number of cards are left in the deck.

Whether or not you choose to fix the dealing alogrythm, another simple fix would be to update showcard() to actually draw cards (with randomly chosen suits if the card dealing alogrythm isn't fixed).

Now there's only one left. I'll wait a few days and finish off Cymon's Games with Reverse. Strangely enough Reverse is another program I've reduced down to sig size, which is where this whole thread started. So that makes the beginning like the end. I didn't choose the order, but it seems fitting. Maybe I'll even change my sig in honor of this thread.

But it's not over. Now the programs are in your hands. Can you improve them? Can you make them prettier, more acurate, or more fun? If you do, post your improvements here!

(By the way, why hasn't anyone asked about the sparse illustrations that have accompanied these programs? Haven't yawl noticed them?)
guesst is offline                         Send a private message to guesst
Reply With Quote