View Single Post
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