View Single Post
Old 10-07-2006, 11:57 PM   #39
guesst
Abandonia Homie
 
guesst's Avatar

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

I'm trying to make up for all the things I promised I'd do but haven't yet done. I'm such a slacker and Cymon's Games has suffered.

Not that anyone but Abi79 even cares.

But, in Pennance I bring you today:
BlackBox

Unfortunately there are better games I could have done my pennance with. This game isn't particularly cool to see played. To get the most out of it you should really play with a piece of graph paper next to you to take notes on. The purpose of the game is to discover the location of 6 spots in a 10x10 field. You can't see the field (it's covered) but you can shoot rays into it and observe where they exit, which will tell you likely places where the spots can be found.

The game actually contains pretty detailed instructions on how the ray reacts to the spots, so I'm gonna let it do all the talking:
Code:
/* Blackbox or AtomSweeper
 * written by Joseph Larson
 * based on a BASIC program 'Blackbox' by Jeff Keton
 * as found in 'More Basic Computer Games' edited by David H. Ahl (c) 1979
 */

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

#define SIZE 10
#define NUM 6
#define FS(a) for (a = 1; a <= SIZE; a++)
#define RS (rand () % (SIZE - 2) + 2)

void drawbox (int b[][SIZE + 2], int opt) { // 1: input coords 2: xy coords
**int x, y;
**
**printf ("\n**");
**FS(x) printf(" %c",(opt < 2) ? '0' + ((4 * SIZE - x + 1) / 10)
****: " 123"[(x / 10)]);
**printf ("\n**");
**FS(x) printf(" %c",'0' + ((opt < 2) ? ((4 * SIZE - x + 1) % 10) : (x % 10)));
**FS(y) {
****printf ("\n%2d", y);
****FS(x) printf (" %c", (opt < 3) ? '+' : (b[x][y]) ? 'O' : '.');
****if (opt < 2) printf (" %-2d", 3 * SIZE - y + 1);
**}
**if (opt < 2) {
****printf ("\n**");
****FS(x) printf(" %c"," 1234"[(SIZE + x) / 10]);
****printf ("\n**");
****FS(x) printf(" %c",'0' + ((SIZE + x) % 10));
**}
**printf("\n\n");
}

void intro (void) {
**printf ("BlackBox\n--------\n"
**"Try to find atoms that are hidden in a Black Box by firing rays into the\n"
**"box and observing where they emerge.\n"
**" 1) A ray that enters a square diagonal to an atom, so that it would be\n"
**"****next to the atom if it continued, is deflected 90 degrees.\n"
**" 2) A ray that is fired directly at an atom is reflected back the way it\n"
**"****came. It will emerge where it was fired.\n"
**" 3) A ray that is traveling so as to pass between two atoms that are one\n"
**"****square away will also be reflected.\n"
**"\t......\n"
**"\t...O..**********\t\t.....****...O\n"
**"\t--\\...Deflection\t\t---O. or ---. Reflection\n"
**"\t..|...**********\t\t.....****...O\n\n"
**"Input the starting place of the ray you want to fire by typing the\n"
**"cooresponding number on the illustration you will be given at the start\n"
**"of the game.\n"
**"If you need to see this illustration again or want to guess the\n"
**"location of the atoms input 0 (zero) for your move.\n"
**"You will gain one point for every reflection, two for every deflection,\n"
**"and 15 for every atom guessed incorrectly. Try for the lowest score!\n\n"
**"Press ENTER to begin.\n");
**getchar (); 
}

void setup (int b[][SIZE + 2]) {
**int x, y, c;

**for (x = 0; x < SIZE + 2; x++) for (y = 0; y < SIZE + 2; y++) b[x][y] = 0;
**for (c = 0; c < NUM; c++) {while (b[x = RS][y = RS]); b[x][y] = 1;
**}
**printf ("%d atoms hidden.\n", NUM);
}

int shoot (int start, int b[][SIZE + 2]) {
**int x, y, dx, dy, temp;

**switch ((start - 1) / (SIZE)) {
****case 0 : x = 1; y = start; dx = 1; dy = 0; break;
****case 1 : x = start - SIZE; y = SIZE; dx = 0; dy = -1; break;
****case 2 : x = SIZE; y = 3 * SIZE + 1 - start; dx = -1; dy = 0; break;
****case 3 : x = 4 * SIZE + 1 - start; y = 1; dx = 0; dy = 1;
**}
**while (1) {
****switch ((b[x][y] * 7) | (2 * b[x + 1][y - 1] + 2 * b[x - 1][y + 1]
******+ b[x + 1][y + 1] + b[x - 1][y - 1])) {
******case 1 : temp = dx; dx = -dy; dy = -temp; break;
******case 2 : temp = dx; dx = dy; dy = temp; break;
******case 3 :
******case 7 : puts ("The shot was reflected."); return 1;
****}
****x += dx; y += dy;
****if (!(x % (SIZE + 1)) || !(y % (SIZE + 1))) {
******if (!x) temp = y;
******else if (!y) temp = 4 * SIZE - x + 1;
******else if (x > SIZE) temp = 3 * SIZE - y + 1;
******else temp = SIZE + x;
******printf ("Ray exited at %d.\n", temp);
******return 2;
****}
**}
}

int endgame (int b[][SIZE + 2], int *s) {
**int c, x, y;
**char input;
**
**printf ("Do you want to guess now? (y/n) ");
**while (!isalpha (input = getchar ()));
**if (tolower(input) != 'y') {
****drawbox(b, 1);
****return 0;
**}
**drawbox(b, 2);
**for (c = 0; c < NUM; c++) {
****printf ("What is the location of atom #%d? <x,y> ", c);
****scanf ("%d %*c %d", &x, &y);
****if (b[x][y] == 1) {
******puts ("\nCorrect");
******b[x][y] = 10;
****} else {
******puts ("\nIncorrect. Plus 15 points.");
*******s += 15;
****}
**}
**printf ("\nYour final score : %d\nHere's the Blackbox.\n**", *s);
**drawbox (b, 3);
**return 1;
}

int playmore (void) {
**char yesno;

**printf ("\nWould you like to play again? ");
**while (!isalpha (yesno = getchar ()));
**if (tolower(yesno) != 'n') return 1;
**return 0;
}


int main (void) {
**int board[SIZE + 2][SIZE + 2], ray, score, done;

**srand (time (NULL));
**intro ();
**do {
****setup (board);
****score = 0;
****drawbox (board, 1);
****done = 0;
****do {
******printf ("Ray # ? ");
******scanf ("%d", &ray);
******if (ray && ray < 4 * SIZE) score += shoot (ray, board);
******if (!ray) done = endgame (board, &score);
****} while (!done);
**} while (playmore ());
**puts ("Goodbye!");
**exit (0);
}
Oh, and I forgot to mention that, yes, this one is a BASIC conversion with liberty taken on the fact that I didn't like the way edge spots were handled, so I made it so no spots would ever be edge spots, and changed absorption to reflection to increase potential mis-direction.

This is a game of solitare where the object is to perfect your technique to get the most acurate reading with the fewest hints. If you find 6 spots on a 10x10 field not to your liking, the code is very happy, if you change a few constants at the top, to customize for you.

Now, I know it's been a while, but the problem was I didn't have my programs with me, and darned if I was going to waste my weekends with my wife and kids on the computer. But now I have the programs with me at school and nothing better to do all day long, so expect the rest of the list to fly by. Only a few left. Make your choice or, if no one chooses, I'll choose for you. But as always, I love your feedback!
  • Reverse (order a list of number by turning them around)
  • Acey Deucy (a card game of highs, lows, and middles)
  • Flash Cards (with pretty output, practice your math)
  • Pickup Piles (1000 games in one, set the rules and play)
  • Hangman (guess the word before you dangle)
  • Rotate (like those sliding block puzzles but that you rotate pieces)
guesst is offline                         Send a private message to guesst
Reply With Quote