Oh, it works! Thank you! ^_^ I'm gonna start underestanding it, still have other functions to create >_<'
Oh, it works! Thank you! ^_^ I'm gonna start underestanding it, still have other functions to create >_<'
Oh, also sir. What does "static const" mean?
static means it's visible to code only within the translation unit (source file) in which it's declared.
const is short for constant, and means you can't change it.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
Oh, okay, thank you! Finally understand something!
Be aware of the difference between const-qualified variables and constants: Question 11.8
Hi again! Quiiick question
How do I use ASCII characters instead of letters (A, D)?Code:void drawgrid(char grid[]) { int i; int j; for (i = -1; i < GRIDHEIGHT; i++) { printf ("\n"); for (j = -1; j < GRIDWIDTH;j++) { printf("%c", randbetween('A','D') ); } } }
I tried to use a heart but everything got messed up
Hey, I tried to use 5 letters instead of 2, and it says there are too many arguments for my randbetween function?
Code:int randbetween(int min, int max) { return rand() % (max - min + 1) + min; } void drawgrid(char grid[]) { int i; int j; for (i = -1; i < GRIDHEIGHT; i++) { printf("\n"); for (j = -1; j < GRIDWIDTH; j++) { printf("%c", randbetween('K', 'L', 'E', 'X', 'S') ); } } }
> and it says there are too many arguments for my randbetween function?
Your compiler is correct.
The function expects 2 arguments, and you passed 5.
You've got two hands, I throw 5 tennis balls at you and say "catch", what are you going to do?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I figured it out ^_^Thanks
Hi there! I was able to draw the grid, and as we all know it's a Bejeweled-like game. The goal is to match 3, 4, or 5 symbols of the same type. However, in my grid it's still possible for it to generate lines with 3, 4, or 5 pre-made matches. I want it to be impossible for the program to generate this, so what do I include?
Code:int randbetween(int min, int max) { int i; i = rand() % (max - min + 1) + min; if ( i == 0 ) { return 'K'; } else if ( i == 1 ) { return 'L'; } else if( i == 2 ) { return 'E'; } else if (i == 3) { return 'X'; } else (i == 4); { return 'S'; } } void drawgrid(char grid[]) { int i; int j; for (i = -1; i < GRIDHEIGHT; i++) { printf("\n"); for (j = -1; j < GRIDWIDTH; j++) { printf("%c", randbetween(0,4) ); } } }
I have NO idea what "Bejeweled" is about. Use [code*] tags [/code*] (without the *'s), and show what you have now, and what you want. That way the diagram will keep it's proper spacing.
I'm sure the solution is simple, but "like Bejeweled" doesn't cut it for me.
Bejeweled is the same as Candy Crush (if you've played it before):
-You are given a grid with (let's say) 4 different symbols, and they are randomly printed in such a way that no 3, 4, or 5 symbols of the same type are printed side by side.
-The goal is to match 3, 4, or 5 symbols of the same type, and once a match has been made, the matched symbols are cleared out and new, random symbols are put in their place.
Hopefully that's understandable?
I want my program NOT to print symbols of the same type side by side each other, like the 3 A's in the second row:
ABCDA
BDAAA
CDABC
DABCD
I want it the program to print a grid, such that no 3, 4, or 5 symbols are printed side by side like this:
ABCDA
BCDAA
ABDCB
CABDA
This is what I have so far:
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> #define GRIDWIDTH 6 #define GRIDHEIGHT 6 #define NUMSYMBOLS 5 void clearscreen(); int randbetween(int min, int max); void drawgrid(char grid[]); int main() { /* Initialize environment */ time_t seconds; int iter; char grid[GRIDWIDTH][GRIDHEIGHT]; char outgrid[GRIDWIDTH][GRIDHEIGHT]; int rowchoice; int colchoice; char matchfound; char maxzeroes; char foundzeroes; int eliminated; int i; int j; int k; time(&seconds); srand((unsigned int) seconds); drawgrid(outgrid[randbetween(0,4)]); printf("\nEnter a choice, 1 for up, 2 for down, 3 for left, 4 for right"); scanf ("%c",&rowchoice ); } void clearscreen() { if (system("cls")) { system("clear"); } } int randbetween(int min, int max) { int i; i = rand() % (max - min + 1) + min; if( i == 0 ) { return 'K'; } else if( i == 1 ) { return 'L'; } else if( i == 2 ) { return 'E'; } else if( i == 3 ) { return 'X'; } else( i == 4 ); { return 'S'; } } void drawgrid(char grid[]) { int i; int j; for (i = -1; i < GRIDHEIGHT; i++) { printf("\n"); for (j = -1; j < GRIDWIDTH; j++) { printf("%c", randbetween(0,4) ); } } }
Last edited by programmingnewb; 08-25-2013 at 05:43 PM.
A simple idea would be to make your game grid up initially with letters (in any order), and then use a while loop to keep making swaps, until you have no repeats in the same row, next to each other.
I don't believe that it would take too many swaps to randomize it as you want.
Last edited by Adak; 08-25-2013 at 06:28 PM.