Jump to content
  • Advertisement

guesst

Member
  • Content Count

    38
  • Joined

  • Last visited

Community Reputation

122 Neutral

About guesst

  • Rank
    Member
  1. guesst

    I'm new with the dev c + +

    It's so weird now going to boards with my old handle. I'm so used to "Cymon" now. The other option is to make Arriba a constant flag. Like this: const int Arriba = 10; int Tecla; Tecla = Arriba; if (Tecla == Arriba) { cout <<"OK"; } Internal to your code this has the desired effect, but the down side is if you ever try doing somethign like "cout <<Arriba;" your output will be the value of Arriba, not the word Arriba. That's because Arriba is now a variable, not a word. Spanish variables. What a trip.
  2. guesst

    Statistics analysis

    Quote:Original post by alvaro For the original problem: You can think of the game as "pick 21 cards; if any of them is the joker you lose, otherwise you win." Now it should be more obvious that the probability of winning is 4/25. For the second problem: What is the victory condition? if it's simply not picking a joker, the best strategy is to pick 12 cards from the first pile, 7 from the second pile and 2 from the third pile, which has a probability of winning of 13/25*13/20*13/15 ~= 0.292933333... So you have improved the odds quite a bit Improved, but still a high chance of failure. Still, I've made it seem like you're odds are better, and I've made the interactions much more... interactive. This whole discussion has been for the purpose of my 7drl project which starts tomorrow, so thanks for your help. What this tells me is that the luck aspect of the gameplay is enough I don't need to worry about throwing combat which might kill you into the mix.
  3. guesst

    Statistics analysis

    Yeah, the math got faster when I realized the canceling out that was happening. (I actually multiplied the fractions and reduced. Duh.) Okay, so how about this, instead of 1 pile I have 4, each pile has a joker somewhere in it. The first 25 cards, the second has 20, the third has 15, the fourth has 10. To win you only need to draw 21 cards from any where. Only it's played like this: Start drawing from the tallest pile, when you don't trust that pile any more, you move on to the next, and so forth until you have 21 piles. So you start on the tallest pile, figuring you have the best odds. But eventually the odds don't favor you there any more, so you move on to the next. Have I significantly increased your odds of winning now or have I just disguised the fact that you're still going to loose more than you win?
  4. DUUUUUUUUUUUH! I kept expanding the first number but ... WHY! Thanks guys.
  5. Quote:Original post by Pseudokai I'd recommend looking at Hamiltonian paths. If you treat each square in the grid as a vertex then it should be exactly what you're looking for. Ooh, fits the description. However, I don't can't find any randomized Hamiltionian path generation algorithms yet. Have to keep looking.
  6. guesst

    dynamicly allocating a 2D array

    I tried that at one point (You can see the code commented out in the full listing above) but for some reason it didn't work, tho whether it was for the same reason or not i don't know. I think i gave up on that thread before my desperate cry for help. I'll try it like that again tomorrow. me tired tonight. too tired to push shift key.
  7. guesst

    dynamicly allocating a 2D array

    Here's the code that's segfaulting: /*robotfindskitten v1600000.150 source code. * *Copyright (C) 1997,1999 Leonard Richardson leonardr@segfault.org * * *Note that this is not the source for the compiled program that comes *with this package (v1600000.200). I don't know where the source for *that is. I don't even know to what extent this code will compile and *run, as I no longer use DOS. As far as I'm concerned, this code has *historical value only. * *If you want this to work like the compiled version, look at the binary *and add the other 50 messages to the array. Also take a look at the problem *near the end where it says "Here's where the problem is." I don't know *what the problem is, but if I said there was one, there probably was one. */ #include <curses.h> #include <time.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define EMPTY -1 #define ROBOT 0 #define KITTEN 1 #define MAXMESSAGES 1000 void instructions(); void draw_robot(); void draw_kitten(); void process_input(int input, int screen[COLS][LINES]); typedef struct object { int x; int y; int color; int character; } OBJECT; OBJECT robot; OBJECT kitten; OBJECT empty; OBJECT bogus[MAXMESSAGES]; int bogus_messages[MAXMESSAGES]; char messages[MAXMESSAGES][80]; int used_messages[MAXMESSAGES]; int numbogus; int nummessages; int main(int argc, char *argv[]) { int screen[COLS][LINES]; int supplied_number; /*Number of bogus OBJECTs, supplied on command line. */ int c, c2; FILE *fp; /* Do general start-of-program stuff. */ nummessages = 0; fp = fopen ("messages.txt", "r"); if (fp == NULL) { strcpy (messages[nummessages++], "This is not a kitten."); strcpy (messages[nummessages++], "That's just an old tin can."); strcpy (messages[nummessages++], "It's an altar to the horse god."); strcpy (messages[nummessages++], "A mere collection of pixels."); strcpy (messages[nummessages++], "TA box of fumigation pellets."); strcpy (messages[nummessages++], "More grist for the mill."); strcpy (messages[nummessages++], "It's a square."); strcpy (messages[nummessages++], "Run away! Run away!"); strcpy (messages[nummessages++], "The rothe hits! The rothe hits!"); strcpy (messages[nummessages++], "This place is called Antarctica. There is no kitten here."); strcpy (messages[nummessages++], "It's a copy of \"Zen and The Art of Robot Maintenance\"."); strcpy (messages[nummessages++], "\"Yes!\" says the bit."); strcpy (messages[nummessages++], "\"No!\" says the bit."); strcpy (messages[nummessages++], "A robot comedian. You feel amused."); strcpy (messages[nummessages++], "A forgotten telephone switchboard."); strcpy (messages[nummessages++], "It's a desperate' plug for Cymon's Games, http://www.cymonsgames.com/"); strcpy (messages[nummessages++], "The letters O and R."); strcpy (messages[nummessages++], "\"Blup, blup, blup\" says the mud pot."); strcpy (messages[nummessages++], "Another rabbit? That's three today!"); strcpy (messages[nummessages++], "Thar's Mobius Dick, the convoluted whale. Arrr!"); strcpy (messages[nummessages++], "This object here appears to be Louis Farrakhan's bow tie."); strcpy (messages[nummessages++], "...thingy???"); strcpy (messages[nummessages++], "Pumpkin pie spice."); strcpy (messages[nummessages++], "Chewing gum and baling wire."); strcpy (messages[nummessages++], "It's the crusty exoskeleton of an arthropod!"); } else { while (fgets (messages[nummessages++], 78, fp)) messages[nummessages - 1][strlen(messages[nummessages - 1]) - 1] = 0; } srand(time(NULL)); initscr (); raw (); noecho(); curs_set(0); nonl(); keypad(stdscr,1); start_color(); init_pair(0, COLOR_WHITE & A_BOLD, 0); /* for text */ init_pair(1, COLOR_WHITE, 0); /* for robot */ for (c = 2; c < COLORS; c++) init_pair(c, c, COLOR_BLACK); empty.x = -1; empty.y = -1; empty.color = 0; empty.character = ' '; if (argc == 1) { numbogus = 20; } else { supplied_number = atoi(argv[1]); if (supplied_number < 0 || supplied_number > nummessages) { printw ("Error: run-time parameter must be between 0 and %d.", nummessages); endwin (); exit(0); } else { numbogus = supplied_number; } } // screen = malloc(COLS * sizeof (int*)); // for (c = 0; c < COLS; c++) screen[c] = malloc(sizeof (int)); /* Now we have the filling in of the various arrays. * Create an array to represent the screen so that we can make sure all * the OBJECTs go on different squares. */ for (c = 0; c <= COLS; c++) { for (c2 = 0; c2 <= LINES; c2++) { screen[c][c2] = EMPTY; } } /* Create an array to ensure we don't get duplicate messages. */ for (c = 0; c < nummessages; c++) { used_messages[c] = 0; bogus_messages[c] = 0; bogus[c] = empty; } /* Now we initialize the various game OBJECTs. * Assign a position to the player. */ robot.x = rand() % COLS; robot.y = rand() % (LINES - 3) + 3; robot.character = '#'; robot.color = 1; screen[robot.x][robot.y] = ROBOT; /* Assign the kitten a unique position. */ do { kitten.x = rand() % COLS; kitten.y = rand() % (LINES - 3) + 3; } while (screen[kitten.x][kitten.y] != EMPTY); /* Assign the kitten a character and a color. */ do { kitten.character = rand() % 254 + 1; } while (kitten.character == '#' || kitten.character == ' '); kitten.color = rand() % (COLORS - 2) + 2; screen[kitten.x][kitten.y] = KITTEN; /* Now, initialize non-kitten OBJECTs. */ for (c = 0; c < numbogus; c++) { /* Assign a unique position. */ do { bogus[c].x = rand() % COLS; bogus[c].y = rand() % (LINES - 3) + 3; } while (screen[bogus[c].x][bogus[c].y] != EMPTY); screen[bogus[c].x][bogus[c].y] = c+2; /* Assign a character. */ do { bogus[c].character = rand() % 254 + 1; } while (bogus[c].character == '#' || bogus[c].character == ' '); bogus[c].color = rand() % (COLORS - 2) + 2;; /* Assign a unique message. */ int index = 0; do { index = rand() % nummessages; } while (used_messages[index] != 0); bogus_messages[c] = index; used_messages[index] = 1; } /* Print instructions. */ clear(); instructions(); clear(); /* Put stuff on the screen. */ attrset (COLOR_PAIR(0)); move(0,0); attron (A_BOLD); printw ("robotfindskitten v22-july-2008"); move(2,0); for (c = 0; c < COLS; c++) addch ('_'); attroff (A_BOLD); move(kitten.y,kitten.x); draw_kitten(); move (3,0); for (c = 0; c < numbogus; c++) { move(bogus[c].y,bogus[c].x); attrset (COLOR_PAIR(bogus[c].color)); addch(bogus[c].character|A_ALTCHARSET); } move(robot.y,robot.x); draw_robot(); int old_x = robot.x; int old_y = robot.y; /* Now the fun begins. */ int input; input = getch(); while (tolower(input) != 'q') { process_input(input, screen); /* Redraw robot, where avaliable */ if (!(old_x == robot.x && old_y == robot.y)) { move(old_y,old_x); addch(' '); move(robot.y,robot.x); draw_robot(); screen[old_x][old_y] = EMPTY; screen[robot.x][robot.y] = ROBOT; old_x = robot.x; old_y = robot.y; } input = getch(); } endwin (); return 0; } /* Given the keyboard input, interprets it. */ void process_input(int input, int screen[COLS][LINES]) { int check_x = robot.x; int check_y = robot.y; int c; switch (input) { case KEY_UP: check_y--; break; case KEY_DOWN: check_y++; break; case KEY_LEFT: check_x--; break; case KEY_RIGHT: check_x++; break; case 0: break; default: /* invalid command */ move(1,0); attrset (COLOR_PAIR(0)); printw("Invalid command: Use direction keys or Press 'Q'."); clrtoeol (); return; } /* Check for going off the edge of the screen. */ if (check_y < 3 || check_y > LINES - 1 || check_x < 0 || check_x > COLS - 1) { return; } /* Check for collision */ if (screen[check_x][check_y] != EMPTY) { switch (screen[check_x][check_y]) { case ROBOT: /* We didn't move. */ break; case KITTEN: /* Found it! */ move(1,0); clrtoeol (); /* The grand cinema scene. */ for (c = 0; c <=3; c++) { move(1, COLS / 2 - 5 + c); addch(' '); move(1,COLS / 2 + 4 - c); addch(' '); move(1,COLS / 2 - 4 + c); if (input == KEY_LEFT || input == KEY_UP) draw_kitten(); else draw_robot(); move(1,COLS / 2 + 3 - c); if (input == KEY_LEFT || input == KEY_UP) draw_robot(); else draw_kitten(); refresh (); napms (600); } /* They're in love! */ move(0,COLS / 2 - 1); attrset (COLOR_PAIR(COLOR_RED)); addch(3|A_ALTCHARSET); addch(3|A_ALTCHARSET); move(0,0); refresh(); napms (1200); attrset (COLOR_PAIR(0)); printw ("You found kitten! Way to go, robot!\n"); getch (); endwin (); exit(0); break; default: move(1,0); attron (A_BOLD); printw (messages[bogus_messages[screen[check_x][check_y]-2]]); clrtoeol (); attroff (A_BOLD); break; } move(2,0); return; } /* Otherwise, move the robot. */ robot.x = check_x; robot.y = check_y; } void instructions() { attrset (COLOR_PAIR(0)|A_BOLD); move(0,0); printw ("robotfindskitten v22-June-2008\n" "Originally by the illustrious Leonard Richardson 1997\n" "Written especially for the Nerth Pork robotfindskitten contest\n" "ReWritten in PDCurses by Joseph Larson\n" "especially for Cymon's Games 2008 HTTP://WWW.CYMONSGAMES.COM\n\n" " In this game, you are robot ("); draw_robot(); attrset (COLOR_PAIR(0)|A_BOLD); printw ("). Your job is to find kitten. This task\n" "is complicated by the existance of various things which are not kitten.\n" "Robot must touch items to determine if they are kitten or not. The game\n" "ends when robotfindskitten. Alternatively, you may end the game by hitting\n" "the Esc key. See the documentation for more information.\n\n" " Press any key to start.\n"); getch(); } void draw_robot() /* Draws robot at current position */ { attrset (COLOR_PAIR(robot.color)); addch(robot.character); } void draw_kitten() /* Draws kitten at current position */ { attrset (COLOR_PAIR(kitten.color)); addch(kitten.character|A_ALTCHARSET); }
  8. Quote:Original post by Umbrae Perhaps an idea is to start with a straight line from start to finish then continually look for ways to put 'kinks' in it, look at two adjacent empty squares and bend the path into it. Keep running this algorithm over the path until it's bent out of shape. Not only do you want to make additions to the path, but also move it for some modifications. The key is to always have a valid path so you never have to validate it and try to solve. That is a possibility and means that I simply insure that I never leave less than 2 spaces next to each other. It also means the in path has to meet up at the out path. It's an idea that bears some thinking out.
  9. Quote:Unicursal: One way to create a random unicursal Maze is to take a perfect Maze, seal off the exit so there's only the one entrance, then add walls bisecting each passage. This will turn each dead end into a U-turn passageway, and there will be a unicursal passage starting and ending at the original Maze's beginning, that will follow the same path as someone wall following the original Maze. The new unicursal Maze will have twice the dimensions of the original perfect Maze it was based on. Small tricks may be done to have the start and end not always be next to each other: When creating the perfect Maze, never add segments attached to the right or bottom walls, so the resulting Maze will have an easy solution that follows that wall. Have the entrance at the upper right, and after bisecting to create the unicursal routing, remove the right and bottom wall. This will result in a unicursal Maze that starts at the upper right and ends at the lower left. Hmmm, limited. Either the beginning and ending will be in the same place or on the edges. I don't like limitations. But they would work. I've mapped out all the past numbrixs as unicursal mazes and am analizing them, trying to see what I can do to make it happen. Thorny problem, this.
  10. Quote:Original post by Hodgman The first thing I thought of is simply to brute force it. Pick a start location, randomly choose a valid direction, repeat. If no valid direction can be chosen, then you're at the end. If there are blank spaces still (cells that aren't visited by the path), then you fail, so start the whole process again. Eventually, chance will give you a valid path. According to this page, a term to search for might be "Unicursal maze". Quote:Unicursal: A unicursal Maze means one without any junctions. Sometimes the term Labyrinth is used to refer to constructs of this type, where "Maze" means a puzzle where choices are involved. A unicursal Maze has just one long snake-like passage that coils throughout the extent of the Maze. It's not really difficult unless you accidentally get turned around half way through and make your way back to the beginning again. Woah, good resource there. Gotta get some sleep, but I'm definitely combing that over tomorrow. Brute forcing would work okay, but you don't need to go back all the way, just to where you can fill in the blank. For that matter, you don't need to finish the maze, just check at every interval if you've made an unreachable space, and if you have back up 3 spaces.... no, that may not work entirely.
  11. Kind of a RobotOdyssey type thing, isn't it? Have to check it out. I love this sort of game.
  12. guesst

    Console Output?

    ascii character 08 is the backspace. You can call it like this: printf ("This should be overwro%citten",8); Heh, look. Comma 8.
  13. guesst

    Who first predicted video game types?

    Yes, I've researched both of those people, of course I know who they are. But I can't find any reference to the statement that I'm looking for. I'm as interested in knowing the types of game this unknown individual predicted would exist as I am in finding out who it was. It's for a paper I'm writing. I'm absolutely stumped.
  14. guesst

    Learning C++

    Okay, how's this: http://www.retroremakes.com/forum2/showthread.php?t=10247. It's a little side project of mine that I'll be making a website for soon enough. It's inspired by the old BASIC type-in books, many program play just like them, but updated to C and C++. I've written almost all of the programs but I hope once there's a website that it'll inspire contributors. I'd love to have a simple example of making an address book or something.
  15. guesst

    AI for an old Nim-like game

    A Google search on Sprague–Grundy theorem led to wikipeda. Following a link on impartial games wherein Chomp is actually mentioned (!) (which I don't know why I didn't find before), which led to a plethora of resources, my favorate being the one that states Quote:Existence of a winning strategy If P has a largest element 1, different from 0, then a trivial strategy-stealing argument shows that the first player wins. (If picking 1 does not win, it is because the opponent has the devastating reply a. But in that case the first player wins by starting with a.) However, the argument is non-constructive: the winning move is unknown. (Emphasis added.) I had to wade through alot of the sort of graduate level peenee waving that gets doctoral degrees without actually solving problems and bugs the h-e-double-hockey-sticks out of me. Dispite Wikipedia's "authorativive" statement Quote:Computers can easily calculate winning moves for this game on two-dimensional boards of reasonable size. ...it seems the only solutions from the game are for fixed sizes and not very dynamic at all. http://www.philipbrocoum.com/munch/winners8x9.txt seems a good resource for analizing the nim numbers that could perhaps be generalized and I'll probably spend a long, long time looking at this list. I think the verticle and horizontal nim numbers need to be compared or perhaps calculated together in some way, but I'm not sure yet. The quest still continues. [Edited by - guesst on January 1, 2008 1:22:00 PM]
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!