Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 23-07-2006, 08:28 AM   #51
Abi79
Home Sweet Abandonia

 
Join Date: May 2005
Location: Oradea, Romania
Posts: 829
Send a message via Yahoo to Abi79
Default

Acey Ducey, Acey Ducey!
Abi79 is offline                         Send a private message to Abi79
Reply With Quote
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
Old 24-07-2006, 06:52 PM   #53
Abi79
Home Sweet Abandonia

 
Join Date: May 2005
Location: Oradea, Romania
Posts: 829
Send a message via Yahoo to Abi79
Default

Quote:
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!
[/b]
Abi is working on the graphics for the other game, but Abi is lazy and doesn't have any imagination, so it might take Abi a while to finish that...

Quote:
(By the way, why hasn't anyone asked about the sparse illustrations that have accompanied these programs? Haven't yawl noticed them?)
[/b]
I have, but when I saw that you stopped adding them, I thought you didn't have more of those.

Quote:
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.[/b]
Funny, eh? Oh, and does the program in your sig actually do something? It wouldn't work in C++ for DOS, without adding the proper libraries (you know what I mean; Stdio, Conio...) and doing that int thing, which I cannot translate into English. I'm curious, but does it work in other compilers? I guess not.
Abi79 is offline                         Send a private message to Abi79
Reply With Quote
Old 24-07-2006, 08:37 PM   #54
guesst
Abandonia Homie
 
guesst's Avatar

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

Yeah, it compiles. In DevC++, as long as you save it as a .c file it works just fine. It give you a few warnings because it says that you aren't including the necessary files, but it will find them and complie the program anyways. There are defaults in C that you don't NEED to #include, but it's good coding practice to. Stdio.h, conio.h, math.h, ctype.h... pretty much any of the basic ones. If it's a custom made header file or library you'll need to #include it, but the rest it's usually smart enough to find on it's own.

I'm pretty sure it works in VC++ as well the same way. That's been a stapel of the international obfscated C code contest for ages.

Did you ask about the illustrations? I'll have to go check.
guesst is offline                         Send a private message to guesst
Reply With Quote
Old 25-07-2006, 06:18 PM   #55
guesst
Abandonia Homie
 
guesst's Avatar

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

<div align="center">Reverse</div>
This game is a simple solitare game. There were a few of these that I made, games that sort of weave a pattern down the screen as you solve them and in the are not all together unpleasant to look at. (Jumping Balls was another and Corral, which may appear here at a future date) Take a look at the overall astetic of the game as it progresses:
Code:
13 12**4**2**5**7 11**8**1 10**6**3 16**9 14 15 ? 3
13 12**4**2**5**7 11**8**1 10**6**3 16 15 14**9 ? 4
13 12**4**2**5**7 11**8**1 10**6**3**9 14 15 16 ? 16
16 15 14**9**3**6 10**1**8 11**7**5**2**4 12 13 ? 13
16 15 14 13 12**4**2**5**7 11**8**1 10**6**3**9 ? 5
16 15 14 13 12**4**2**5**7 11**8**9**3**6 10**1 ? 16
 1 10**6**3**9**8 11**7**5**2**4 12 13 14 15 16 ? 4
 1 10**6**3**9**8 11**7**5**2**4 12 16 15 14 13 ? 4
 1 10**6**3**9**8 11**7**5**2**4 12 13 14 15 16 ? 7
 1 10**6**3**9**8 11**7**5 16 15 14 13 12**4**2 ? 15
 1**2**4 12 13 14 15 16**5**7 11**8**9**3**6 10 ? 3
 1**2**4 12 13 14 15 16**5**7 11**8**9 10**6**3 ? 14
 1**2**3**6 10**9**8 11**7**5 16 15 14 13 12**4 ? 13
 1**2**3**4 12 13 14 15 16**5**7 11**8**9 10**6 ? 7
 1**2**3**4 12 13 14 15 16**6 10**9**8 11**7**5 ? 12
 1**2**3**4**5**7 11**8**9 10**6 16 15 14 13 12 ? 6
 1**2**3**4**5**7 11**8**9 10 12 13 14 15 16**6 ? 11
 1**2**3**4**5**6 16 15 14 13 12 10**9**8 11**7 ? 10
 1**2**3**4**5**6**7 11**8**9 10 12 13 14 15 16 ? 8
 1**2**3**4**5**6**7 11 16 15 14 13 12 10**9**8 ? 9
 1**2**3**4**5**6**7**8**9 10 12 13 14 15 16 11 ? 7
 1**2**3**4**5**6**7**8**9 11 16 15 14 13 12 10 ? 7
 1**2**3**4**5**6**7**8**9 10 12 13 14 15 16 11 ? 6
 1**2**3**4**5**6**7**8**9 10 11 16 15 14 13 12 ?
Okay, it ain't Georga O'Keffe, but it ain't bad for rows of numbers.

The object of this game is to order a list of numbers by reversing parts of the list. Because the game is at it's root so simple I made a sig version, which in honor of this posting is now my current sig. But I'll re-post it here incase my sig ever changes again:
Code:
main(){long l[16],c,d,t;srand(time(0));for(t=d=c=0;c<16;c++){while(1<<(l[c]=rand
()%16+1)&d);d|=1<<l[c];}for (;c>0;printf ("%2d ",l[--c]));do{printf("? ");scanf(
"%d",&d);if(d>1&&d<=16){for (c=0;c<(d/2);c++){l[c]^=l[d-c-1];l[d-c-1]^=l[c];l[c]
^=l[d-c-1];}t++;}for(c=16;c>0;printf("%2d ",l[--c]));for(c=0;c<15&&l[c]>l[c+1];c
++);}while(d&&c<15);if(d)printf("\nThank you for playing! Won in %d moves!",t);}
This game can solved in a minimum amout of moves if you mearly move the first number to the end of the line, then where it belongs, and proceed with the next. So it becomes possible to grade your performance, comparing how many moves it took against the "maximum" number moves it should take, which happens at the end of the game.

This game too is a BASIC adapatation.

Here's the full version:
Code:
/* Reverse
 * by Joseph Larson 2005
 * Inspired by a BASIC game of the same name by Peter Sessions
 * as found in 'BASIC Computer Games' edited by David H. Ahl (c) 1978
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

#define X 16

int main (void) {
**int list[X], c, d, turns;
**long mask;
**char yn;
**
**srand (time(NULL));
**printf ("Reverse\n-------\n\n"
****"This is the game of Reverse. To win all you have to do is arrange a list\n"
****"of numbers (1 through %d) in numerical order left to right.\n"
****"To move, you input how many numbers from the right you want to reverse.\n"
****"You will no doubt like this game but, if you want to quit just input '0'\n"
****"as your move.\n\n", X);
**do {
****mask = 0;
****for (c = 0; c < X; c++) {
******while (1 << (list[c] = rand () % X + 1) & mask);
******mask |= 1 << list[c];
****}
****turns = 0;
****puts ("Here we go...\n");
****do {
******putchar ('\t');
******for (c = X; c > 0;) printf ("%2d ",list[--c]);
******printf ("\t? ");
******scanf ("%d", &d);
******if (d > 1 && d <= X) {
********for (c = 0; c < (d / 2); c++) {
**********list[c] ^= list[d - c - 1];
**********list[d - c - 1] ^= list[c];
**********list[c] ^= list[d - c - 1];
********}
********turns++;
******} else printf ("You can not reverse %d. Try again.\n", d);
******for (c = 0; c < X - 1 && list[c] > list [c + 1]; c++);
****} while (d && c < X - 1);
****if (d) {
******putchar ('\t');
******for (c = X; c > 0;) printf ("%2d ",list[--c]);
******printf ("\n\nYou ordered the list in %d moves.\n", turns);
******if (turns > X * 2 - 3) 
********printf ("But it shouldn't have taken more than %d moves.\n" , X * 2 - 3);
******if (turns <= X)
********puts ("Wow, you are either extremely good, or extremely lucky.");
****}
****printf ("\nWould you like to try another? (y/n) : ");
****while (!isalpha (yn = getchar ()));
**} while (yn == 'y');
**puts ("Good bye for now then!");
**exit (0);
}
The method of reversing the list uses an abuse of the binary xor (^ in C) operator. Variable A is xor(^=)ed with variable B, changing variable A to be xor-ed version of both A and B, destroying the original value of A. Variable B is xor-ed with variable A, which has the effect of making varaible B now the original value of variable A. Variable A is now xor-ed with B, which is what A used to be, effectivly reversing the original xor command but ending with A now holding the original value of B. It's very clever, works every time, and negates a temporary holding variable to swap values.

Well, that's it. But this is not the end! Cymon's Games may slow down for a while, but there are games that either need to be rewritten or written in the first place. Plus, I need to install Borland and try making my programs work on that. Any questions you have, any improvements, this topic isn't closed. Do you have your own games you want to contribute? Feel free!

So what do you have to look forward to? Now, don't go requesting one or the other. I'll get to them when I get to them. But here's a few games:
Complete but didn't make the list (usually because they're pretty lame):
  • Hurkle - Your standard, "go north", "go south" hint game with added dimension up and down.
  • Nicomanchis - An ancient number guessing trick. Not much of a game.
  • Risk Dice - Ever get tired of the constant battling in Risk? Automate it!
Complete but buggy:
  • Camel - A race across the Gobi!
  • Corral - Catch a horse in a 1D corral
Games I'm still planning to write:
  • Wumpus - Saving this one for C++
  • Lava Lamp - An "animated" version of a Basic game found here.
  • Some sort of choose your own adventure maker/player
  • Some sort of picture decoder like this or this one, but perferably more robust.
But until those show up, thanks all for the interest. I hope some of you, some day, will be inspired to program a few yourself. You can do what I did, go check out the archives of 101 Basic Games, More Basic Games, Big Basic Games and see if they don't spark some inspiration in you.
guesst is offline                         Send a private message to guesst
Reply With Quote
Old 26-07-2006, 08:58 AM   #56
Abi79
Home Sweet Abandonia

 
Join Date: May 2005
Location: Oradea, Romania
Posts: 829
Send a message via Yahoo to Abi79
Default

Hurkle, Hurkle, where is Hurkle?
Abi79 is offline                         Send a private message to Abi79
Reply With Quote
Old 28-07-2006, 03:55 AM   #57
guesst
Abandonia Homie
 
guesst's Avatar

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

<div align="center">Hurkle</div>
I mentioned that this isn't that great a game. Well, at least it's short.

So what is a Hurkle? Why do we hunt them and their cousins the mugwumps so? Why do these elusive prizes inspire such games of hide and seek? What does a hurkle or mugwump look like?

In this game the Hurkle has evolved from it's original incarnation and has gained the power of flight. Thus you must find the hurkle not just in x and y, but in z as well.

Code:
/* Hurkle hunt in 3D
 * by Joseph Larson 2005
 * Inspired by a BASIC program by Bob Albrecht
 * 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 MG 10
#define SIZE 10

int main (void) {
**int hx, hy, hz, x, y, z, c;
**char yesno;

**printf ("Hurkle Hunt in 3D\n\n"
**"A hurkle is a cute little creature, that in this game can fly. The hurkle\n"
**"is hiding in a region %d x %d x %d. After every guess your special hurkle\n"
**"locator will tell you which way you need to go. Keep in mind that 1,1,1 is\n"
**"the lowest northwest corner.\n", SIZE, SIZE, SIZE);
**printf ("Input your move by typing the x then y then z coordinate seperated\n"
**"by commas like \"1,2,3\"\n\n");
**srand (time (NULL));
**do {
****hx = rand () % 10 +1;
****hy = rand () % 10 +1;
****hz = rand () % 10 +1;
****printf ("The hurkle is ready.");
****for (c = 1; c <= MG && !(x == hx && y == hy && z == hz); c++) {
******printf ("\nWhere do you want to look? (X,Y,Z) : ");
******scanf ("%d %*c %d %*c %d", &x, &y, &z);
******printf ("The hurkle is ");
******if (y < hy) printf ("south");
******if (y > hy) printf ("north");
******if (x < hx) printf ("east");
******if (x > hx) printf ("west");
******if ((x != hx || y != hy) && z != hz) printf (" and ");
******if (z < hz) printf ("up");
******if (z > hz) printf ("down");
****}
****if (c <= MG) printf ("HERE!\nYou found the hurkle!\n\n");
****else printf ("\nThats %d trys and you didn't find the hurkle.\n"
******"The hurkle was hiding at %d, %d, %d.\n\n", MG, hx, hy, hz);
****printf ("Would you like to play again? (y/n) ");
****while (!isalpha (yesno = getchar()));
**} while (tolower (yesno) != 'n');
**printf ("Good bye for now!");
**exit (0);
}
Aside from being short, the reason this game was too lame for me to include on the list is that there is no modivation for the hurkle to hold still, yet it does, no modivation for us to not just spot the hurkle where it's at, but we don't, and any attempts to resolve these issues are contrived. The game is academic at best. It's not even that fun to play. Just choose a spot in the center, and then subdivide the distance remaining in whatever direction indicated. You'll win every time. The only surprise is if you find it on your second or third guess. Adding the third dimension was an attempt to complicate the game by way of making one more thing to keep track of, and in that it worked. But it didn't up the satisfaction of winning much for some reason. Not for me anyways.

However, there's hope that in your home the hurkle will find more love than he has found in mine.
guesst is offline                         Send a private message to guesst
Reply With Quote
Old 30-12-2006, 12:04 PM   #58
The Bard
Abandonia Bard
 
The Bard's Avatar


 
Join Date: Feb 2006
Location: Velika Gorica, Croatia
Posts: 117
Default

I see that this is a dead thread, and even though I don't have any intentions on reviving it, I read all of it, and I just had to post this thankyou message. You see, I am an wannabe programmer, and at school, I'm trying to qualify myself on the ACSL, but lately I've been losing enthusiasm for learning and practising, and this thread was exactly what I needed to give me a little bumb ahead. After reading thru all of these programs, even though I work in c++ I understood most, I'm going to get to work, and advance to the recursion problems I just can't get... Again, thank you...
__________________
Founder of F.A.G., Free Abandonia Group
The Bard is offline                         Send a private message to The Bard
Reply With Quote
Old 02-01-2007, 08:58 PM   #59
haakjay
Forum hobbit

 
Join Date: Jan 2007
Location: ,
Posts: 35
Default

Thats really cool. My dad learned me Visual Basic and the BASIC dragon 64 uses. I have learned some Macromedia Actionscript to. And a bit GLBasic.

I'm 13 :P
haakjay is offline                         Send a private message to haakjay
Reply With Quote
Old 21-02-2007, 09:15 AM   #60
nitro
Forum hobbit

 
Join Date: Jan 2007
Location: Nunspeet, Netherlands
Posts: 31
Default

These are some very nice examples. I didn't try them all, but the ones I tried all worked good.

I have only one piece of advice. If you write code with the purpose of sharing it, it is a good practice to add a lot of comment to the code, so others can read it easily. Especially when it is about complicated algorithms like the AI in some of the games.

I also wrote a version of battleship in VB and it is nice to see that you use the same algorithm.
nitro is offline                         Send a private message to nitro
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Happy Birthday Guesst Japo Birthdays & Celebrations 8 06-07-2007 09:50 AM
Happy Birthday, Guesst Shrek Blah, blah, blah... 10 08-07-2006 09:31 AM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 12:21 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.