Bingo with words

This is a discussion on Bingo with words within the C Programming forums, part of the General Programming Boards category; I want to make a BINGO game; however, instead of the usual where one calls out "B1", I want to ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    10

    Bingo with words

    I want to make a BINGO game; however, instead of the usual where one calls out "B1", I want to use words instead. I know, for the most part, how to randomize a given interval of numbers, BUT how would I randomly assign words of a specific alphabetic interval into a bingo square. For example, I want to put 3 words per square, and in the "B" column, only words beginning with a,b,c,d,e. that have already been created in--->
    Code:
    char BingoWords[WORDS][LENGTH]={aardvark, bee, cat, dog, eel,.......}
    Thanks. Hoping for some good advice.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    First, I think your array definition should be
    Code:
    char *BingoWords[]={"aardvark","bee", "cat","dog","eel",.......}
    You can generate random numbers to represent an interval and select the corresponding elements from the array. For example, if you generate a random number in the range 0-4 inclusive you can use the result to select among the words you listed.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    10
    ok, i'll try that. Thank you.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by R.Stiltskin View Post
    First, I think your array definition should be
    Code:
    char *BingoWords[]={"aardvark","bee", "cat","dog","eel",.......}
    You can generate random numbers to represent an interval and select the corresponding elements from the array. For example, if you generate a random number in the range 0-4 inclusive you can use the result to select among the words you listed.
    I'm not sure what difference this makes - char BingoWords[x][y] will become a char * for all intents and purposes when used as a 1D array.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    10
    I will be defining [WORDS][LENGTH]

    for example:
    Code:
    #define WORDS 75
    #define LENGTH 30

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code tag slashes are forward slashes, not backward leaning slashes.

    '/', instead of '\'.

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    10
    any hints or ways I should do this (i.e. example code)? It has been awhile since I have done strings/arrays, etc.

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Quote Originally Posted by matsp View Post
    I'm not sure what difference this makes - char BingoWords[x][y] will become a char * for all intents and purposes when used as a 1D array.

    --
    Mats
    Aesthetics, maybe. Why define a fixed wordlength?

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by R.Stiltskin View Post
    Aesthetics, maybe. Why define a fixed wordlength?
    I agree that there is no reason, but it's also not fixing the original posters problem in itself, so why comment on it? [Yes, I know, I comment on meaningless fixes quite often].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Feb 2009
    Posts
    10
    I am having trouble...
    1) Assigning the words to each space on the card,
    2) Display the bingo card (grid-format, rows/columns) to the user (for both players)
    3) Calling out a word, and
    4) Covering a square if your word is called out.

    Please help. Thanks everyone!

  11. #11
    Registered User
    Join Date
    Feb 2009
    Posts
    10
    any other comments/help please??. I'm not trying to be annoying/pushy; however, I just need help. Thanks everybody.
    Last edited by smitty007; 04-09-2009 at 12:28 PM.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Try one step at a time. Let's go with #1. Do you have a method of drawing your card? Seems like it should be taking a list of words to draw along the card. Make that function, and test it in a stand alone program. Post that and where you're stuck.
    Code:
    #includestuffhere
    
    (type) drawcard ( (argument )
    {
        your stuff here
    }
    
    int main( void )
    {
        drawcard( (your arguments ) );
        return 0;
    }
    Let us know what you're having problems with specifically.


    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    Registered User
    Join Date
    Feb 2009
    Posts
    10
    Ok, here is my full code, so far.... I am using codeblock (cbp) on Mac. So far, I have printed out a grid; however, where I want the random words to go, I get "NULL".
    Please Help Me. Thanks Here
    Code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    
    int main()
    {
    
        char BingoWords[75][30]={"acid","atom","average","axis","base",
    	"bonding","circuit","chemical","dispersion","derivative",
    	"electricity","electron","energy","engineer","equation","force",
    	"friction","flammable","fluorine","fusion","if-then-else",
    	"getchar","gets","grams","gas","ideal gas law","integer",
    	"inertia","integral","joule","kilogram","Kalvin","liter","liquid",
    	"longitude","meter","math","mole","milliliter","molecule","Newton",
    	"neutron","nucleus","optics","orbitals","p-orbital","pounds",
    	"proton","pressure","quark","resistor","s-orbital","science",
    	"scientist","stoichiometry","strain","stress","solution","time",
    	"tension","Uranium","variables","variance","velocity","virtual",
    	"waves","wavelength","weight","x-axis","X-ray","Xenon","y-axis",
    	"Yttrium","z-axis","Zinc"};
        int i;
        char *card[5][5];
    	//about();
    	printf("	  WELCOME TO WORD-BINGO!\n");
    	printf("This is a two player game.  Each player is given one BINGO Card");
    
        gets(*BingoWords);
    	for(i=0;i<=15;i++){
    
    		//B column
    		if((*BingoWords[0]=='a')||(*BingoWords[0]=='A')||
    			(*BingoWords[0]=='b')||(*BingoWords[0]=='B')||
    			(*BingoWords[0]=='c')||(*BingoWords[0]=='C')||
    			(*BingoWords[0]=='d')||(*BingoWords[0]=='D')||
    			(*BingoWords[0]=='e')||(*BingoWords[0]=='E'))
                    *card[i][0]=(rand()%15+1 * i);
    	}
    		//I column
        for(i=16;i<=30;i++){
    		if((*BingoWords[0]=='f')||(*BingoWords[0]=='F')||
    			(*BingoWords[0]=='g')||(*BingoWords[0]=='G')||
    			(*BingoWords[0]=='h')||(*BingoWords[0]=='H')||
    			(*BingoWords[0]=='i')||(*BingoWords[0]=='I')||
    			(*BingoWords[0]=='J')||(*BingoWords[0]=='j'))
                    *card[i][1]=(rand()%15+1 * i);
    		}
    		//N column
        for(i=31;i<=45;i++){
    		if((*BingoWords[0]=='k')||(*BingoWords[0]=='K')||
    			(*BingoWords[0]=='l')||(*BingoWords[0]=='L')||
    			(*BingoWords[0]=='M')||(*BingoWords[0]=='m')||
    			(*BingoWords[0]=='n')||(*BingoWords[0]=='N')||
    			(*BingoWords[0]=='o')||(*BingoWords[0]=='O'))
                    *card[i][2]=(rand()%15+1 * i);
    		}
    		//G column
        for(i=46;i<=60;i++){
    		if((*BingoWords[0]=='p')||(*BingoWords[0]=='P')||
    			(*BingoWords[0]=='q')||(*BingoWords[0]=='Q')||
    			(*BingoWords[0]=='r')||(*BingoWords[0]=='R')||
    			(*BingoWords[0]=='s')||(*BingoWords[0]=='S')||
    			(*BingoWords[0]=='t')||(*BingoWords[0]=='T'))
                    *card[i][3]=(rand()%15+1 * i);
        }
    
        for(i=61;i<=75;i++){
    		//O column
    		if((*BingoWords[0]=='U')||(*BingoWords[0]=='u')||
    			(*BingoWords[0]=='v')||(*BingoWords[0]=='V')||
    			(*BingoWords[0]=='W')||(*BingoWords[0]=='w')||
    			(*BingoWords[0]=='x')||(*BingoWords[0]=='X')||
    			(*BingoWords[0]=='Y')||(*BingoWords[0]=='y')||
    			(*BingoWords[0]=='z')||(*BingoWords[0]=='Z'))
                    *card[i][4]=(rand()%75+1 * i);
        }
    
    		printf("\n");
            printf("|	B	|");
            printf("	I	|");
            printf("	N	|");
            printf("	G	|");
            printf("	O	|");
            printf("\n");
    		printf("|	%s	|", card[i][0]);
            printf("	%s	|", card[i][1]);
            printf("	%s	|", card[i][2]);
            printf("	%s	|", card[i][3]);
            printf("	%s	|", card[i][4]);
            printf("\n");
            printf("|	%s	|", card[i][0]);
            printf("	%s	|", card[i][1]);
            printf("	%s	|", card[i][2]);
            printf("	%s	|", card[i][3]);
            printf("	%s	|", card[i][4]);
            printf("\n");
            printf("|	%s	|", card[i][0]);
            printf("	%s	|", card[i][1]);
            printf("	%s	|", card[i][2]);
            printf("	%s	|", card[i][3]);
            printf("	%s	|", card[i][4]);
            printf("\n");
            printf("|	%s	|", card[i][0]);
            printf("	%s	|", card[i][1]);
            printf("	%s	|", card[i][2]);
            printf("	%s	|", card[i][3]);
            printf("	%s	|", card[i][4]);
            printf("\n");
            printf("|	%s	|", card[i][0]);
            printf("	%s	|", card[i][1]);
            printf("	%s	|", card[i][2]);
            printf("	%s	|", card[i][3]);
            printf("	%s	|", card[i][4]);
            printf("\n");
    
            //player2
            printf("\n\n");
            printf("|	B	|");
            printf("	I	|");
            printf("	N	|");
            printf("	G	|");
            printf("	O	|");
            printf("\n");
            printf("|	%s	|", card[i][0]);
            printf("	%s	|", card[i][1]);
            printf("	%s	|", card[i][2]);
            printf("	%s	|", card[i][3]);
            printf("	%s	|", card[i][4]);
            printf("\n");
            printf("|	%s	|", card[i][0]);
            printf("	%s	|", card[i][1]);
            printf("	%s	|", card[i][2]);
            printf("	%s	|", card[i][3]);
            printf("	%s	|", card[i][4]);
            printf("\n");
            printf("|   %s	|", card[i][0]);
            printf("    %s	|", card[i][1]);
            printf("    %s	|", card[i][2]);
            printf("    %s	|", card[i][3]);
            printf("    %s	|", card[i][4]);
            printf("\n");
            printf("|	%s	|", card[i][0]);
            printf("	%s	|", card[i][1]);
            printf("	%s	|", card[i][2]);
            printf("	%s	|", card[i][3]);
            printf("	%s	|", card[i][4]);
            printf("\n");
            printf("|	%s	|", card[i][0]);
            printf("	%s	|", card[i][1]);
            printf("	%s	|", card[i][2]);
            printf("	%s	|", card[i][3]);
            printf("	%s	|", card[i][4]);
            printf("\n");
    
    	return (0);
    }

  14. #14
    Registered User
    Join Date
    Feb 2009
    Posts
    10
    I can't really get to the other functions given I can't really display the BINGO card correctly. Thanks for looking. I am looking forward to your help.

  15. #15
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You need to make a buffer, which is longer than the longest word, with enough length to be padded on either side with spaces (and room for a newline). Then, you find out how long the word is. Now:

    lefthandspaces = ( buffersize - wordlength ) / 2

    Say the buffer is 12 characters. Say the word is 10.

    left hand spaces = ( 12 - 10 ) / 2 = 1

    Put the left hand spaces in first. Then add the word onto the end of it. Then add the right hand spaces and a newline.


    Quzah.
    Hope is the first step on the road to disappointment.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 02:22 PM
  3. Problem with malloc() and sorting words from text file
    By goron350 in forum C Programming
    Replies: 11
    Last Post: 11-30-2004, 10:01 AM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21