View Single Post
Old 22-06-2006, 02:43 AM   #1
guesst
Abandonia Homie
 
guesst's Avatar

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

@Beefonthebone - You should try this one. I think you'll find that even before it starts learning (which it only does when it loses) it'll regularly teach you a thing or two about playing the game. It's quite fun.

Without provocation or invition I will choose the next game, since no one cast a vote. Plus if all goes well I won't have time tomorrow...

Stars/Trap/Letter Guess

Oh yeah, 3 in one today. These games are all kind of variations on a theme. The sort of "guess what I'm thinking" games that entertained me so as a child. I figured no one would vote for these so I'm picking them before they're the last left on the field.

The benifit to these games is they are extremely simple and therefore extremly short. This is the sort of game that if you're writing your first game you'd want to write. (Not sure that came out ...good.) Two out of three of these are adapted from BASIC programs. I've linked the book that I got them from before, so I'm not going to worry about it now. I cracked all of these out in about a day. The challange was to not make them all look like I just edited a few lines between them. As they stand I'm not sure how successful I was at that. They all consist of only a main function and a few loops. They were just so small it seemed unnecessary to strech them out more than that.

They are also so abstract that, besides "Stars" I had nothing with which to make an illustration of. I haven't made illustrations for all of them, but the point is how would I even illustrate the first two? Ah well, here we go:

Letter Guess. This is the "higher/lower" sort of hint system. There exists a well defined method for finding the subject in question in the least number of guesses, so the game will actually tell you in the end if you took too long.

Technical note, I had actually inlined the BEFORE/AFTER bit, but took it out because as simple as the program is I didn't want to confuse new programmers with what is really a pretty odd looking bit of code.
Code:
/* Letter Guess Game
 * by Joseph Larson 2005
 * Inspired by the BASIC game 'Letter' written 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>

int main (void) {
**char input, goal;
**int num;

**srand(time(NULL));
**printf ("Guess My Letter Game\n\n");
**do {
****goal = rand() % 26 + 'A';
****num = 0;
****printf ("I have a letter between A and Z.\n");
****do {
******num ++;
******printf ("Guess #%d (A - Z) : ", num);
******do input = getchar (); while (!isalpha (input));
******input = toupper (input);
******if (input != goal) {
********printf ("\nNo, my letter comes ");
********if (input < goal) printf ("AFTER");
**********else printf ("BEFORE");
********printf (" your guess.\n");
******}
****} while (input != goal);
****printf ("\nYou got it! It took you %d tries to guess my letter.\n", num);
****if (num >= 4) printf ("I'm sure you could do better, though.\n");
****printf ("\nDo you want to play again? (y/n) ");
****do input = getchar (); while (!isalpha (input));
**} while ((input == 'y') || (input == 'Y'));
**printf ("\nGoodbye.\n");
**exit (0);
}
In Trap you try to surround the mystery number by choosing a high and a low number. Hints therefore come in 3 flavors, high, low, or trapped. To make the game more challenging you could make the high and low message exactly the same. Still, it's easy to develop a method to narrow your options fast.
Code:
/* Trap
 * written by Joseph Larson 2005
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>

#define MAX 100
#define MG 8

int main (void) {
**int x, h, l, try, temp;
**char yesno;

**printf ("Trap\n----\n"
**"In this game you have to try to guess a number between 1 and %d by\n"
**"trapping it. Every guess you type a low and high number seperated by a\n"
**"comma (like \"15, 30\") and you'll be told if the number you are trying to\n"
**"find is between your number. When you think you have it type the same\n"
**"number for both the high and low guess. And remember, you only have %d\n"
**"guesses to find the number\n"
**"Good luck!\n\n", MAX, MG);
**srand (time (NULL));
**do {
****x = rand () % MAX + 1;
****printf ("I have a number. You have %d guesses.\n", MG);
****for (try = 1; try <= MG && !(l == h && h == x); try ++) {
******printf ("\nGuess %d (low , high) : ", try);
******scanf ("%d %*c %d", &l, &h);
******if (l > h) { temp = h; h = l; l = temp;}
******if (l <= x && x <= h)
********printf ("You've trapped my number.\n");
******else printf ("My number is %s than your guesses.\n",
******(l > x) ? "lower" : "higher");
****}
****if (l == h && h == x) printf ("I am undone! You caught my number.\n\n");
****else printf ("Ha ha! That's %d guesses. My number was %d.\n\n", MG, x);
****printf ("Do you want to do play again? (y/n) ");
****while (!isalpha (yesno = getchar ()));
**} while (tolower (yesno) == 'y');
**printf ("Until next time then!\n");
**exit (0);
}
The last is Stars. The hints in Stars are sort of a geiger counter giving a visual representation of how close you're getting to the target. You'll find jumping around too much will only confuse you. Creeping up on the number is a much better idea.
Code:
/* Seeing Stars */
/* By Joseph Larson 2005 */
/* Number guessing game inspired by the BASIC game "Stars" 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 <math.h>
#include <ctype.h>

#define MAX 100
#define MAX_GUESS 10

int main () {
**int goal, guess, c, wins, loses;
**char yesno;
**float d;
**
**srand(time(NULL));
**wins = 0;
**loses = 0;
**printf ("Seeing Stars\n------------\n"
**"This is a number guessing game with a twist. After every guess you\n"
**"will be given a number of stars to tell you how close you are to the\n"
**"number you are trying to guess. The more stars you see, the closer\n"
**"you are.\n"
**"You only have %d guesses, so think quick.\n\n", MAX_GUESS);
**do {
****goal = rand() % MAX + 1;
****guess = 0;
****printf ("\nI'm thinking of a number between 1 and %d.", MAX);
****for (c = 0; c < MAX_GUESS && guess != goal; c++) {
******printf ("\nWhat is your guess? ");
******scanf ("%d", &guess);
******for (d = MAX; (int)d > abs(guess - goal); d /= 2) printf ("**");
****}
****if (guess != goal) {
******printf ("\nSorry, thats %d guesses. My number was %d.\n", MAX_GUESS, goal);
******loses ++;
****} else {
******printf ("******\nBingo! You got my number.\n");
******wins ++;
****}
****printf ("Do you want to play again? (y/n) ");
****while (!isalpha (yesno = getchar()));
**} while (tolower (yesno) != 'n');
**printf ("\nWell then, you won %d out of %d games, or %d%%.\n", 
****wins, wins + loses, wins * 100 / (wins + loses));
**exit (0);
}
Still plenty left. Tell me what looks good and I'll give it to you.
  • Battleship (like the board game vs the computer)
  • Cel Life (multi-player version of John Conway's game of Life)
  • Pickup Piles (1000 games in one, set the rules and play)
  • Flash Cards (with pretty output, practice your math)
  • Black Box (find molecules in the inky depths)
  • Hangman (guess the word before you dangle)
  • Rotate (like those sliding block puzzles but that you rotate pieces)
  • Acey Deucy (a card game of highs, lows, and middles)
  • Reverse (order a list of number by turning them around)
guesst is offline                         Send a private message to guesst
Reply With Quote