Thread: Boggle Game Help

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    3

    Post Boggle Game Help

    Hello everyone, I am making a game called Boggle as I love the game a lot and used to play online. I am making it with the help of code which I found over the internet as I have to apply BACKTRACKING.

    The error on my reference code is that It is not asking the user to enter the Words so that it will check with the dictionary and let the user know if the word is available in dictionary or not.

    The output I am getting is: could not find dictonary file\n or puzzle file is missing
    How can I fix this error so that it will bypass and ask the user to enter the word.

    Reference Program:

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<malloc.h>
    #define N 4
    char matrix[N][N];
    void
    show(char mat[N][N])
    {
        int k,j;
        
            for(k=0;k<N;k++)
            {
                for(j=0;j<N;j++)
                {
                    printf("%c ",mat[k][j]);
                }
            printf("\n");
            }
    }
    int
    graph(int row,int col,char ch[],int p,char mat[N][N])
    {
        int i,r,row1,col1,counter;
        //printf("%d %d %d\n",row,col,p);
        int com[8][2]={        {-1,0},
                              {-1,+1},
                               {0,+1},
                               {+1,+1},
                               {+1,0},
                               {+1,-1},
                               {0,-1},
                               {-1,-1}};
        
        if(mat[row][col]==ch[p])
        {
            //printf("word=%c \n",mat[row][col]);
            mat[row][col]=0;
            p=p+1;
            
        }
        
        else
        return 0;
        //printf("\n\n");
        if(strlen(ch)==p)
        {
            printf("%s\n",ch);
            return 1;
        }
        row1=row;
        col1=col;
        for(i=0;i<8;i++)
        {    row1+=com[i][0];
            col1+=com[i][1];
            
            if(mat[row1][col1]>0&&row1>=0&&col1>=0&&row1<N&&col1<N)
            {    
                //printf("grat=%d %d %c\n",row1,col1,mat[row1][col1]);
                
                r=graph(row1,col1,ch,p,mat);
                //printf("result=%d %d %d %d\n",row1,col1,p,r);
                mat[row1][col1]=matrix[row1][col1];
                row1=row;
                col1=col;
                //printf("result=%d %d %d %d\n",row1,col1,p,r);
                if(r==1)
                return 1;
            }
            else
            {
            row1=row;
            col1=col;
            }
        }
        mat[row][col]=matrix[row][col];
        //printf("\n\n");
        //show(mat);
        return 0;
    }
    struct node
    {
        char info[20];
        struct node *next;
    };
    typedef struct node node;
    node*
    getnode(void)
    {
        node *temp;
        temp=(node*)malloc(sizeof(node));
        return temp;
    }
    int
    main(int argc,char *argv[])
    {
        
        char t,mat[N][N],temp1[50],tempc;
        int i=0,j=0,flag=0,r,k;
        if(argc<3)
        {
            printf("could not find dictonary file\n or puzzle file is missing\n");
            return 0;
        }
        FILE *fp,*fp1;
        fp=fopen(argv[1],"r+");
        fp1=fopen(argv[2],"r+");
        while(fscanf(fp1,"%c",&tempc)!=EOF)
        {
            if(tempc==' ');
            else
            {
                if(tempc=='\n')
                {
                    i++;
                    j=0;
                }
                else{
                    //printf("%d %d %c\n",i,j,tempc);
                    matrix[i][j++]=tempc;
                }
            
            }
        }
        //show(matrix);
        node *start,*ptr;
        start=NULL;
        ptr=start;
        while(fscanf(fp,"%s",temp1)!=EOF)
        {
            node *temp;
            temp=getnode();
            strcpy(temp->info,temp1);
            temp->next=NULL;
                if(ptr==NULL)
                {
                    ptr=temp;
                    start=temp;
                }
                else
                {
                    
                    ptr->next=temp;
                    ptr=ptr->next;
                }
                temp=NULL;
        }
        
        for(i=0;i<N;i++)
            {
                for(j=0;j<N;j++)
                {
                    mat[i][j]=matrix[i][j];
                }
            }
        //show(mat);
        while(start!=NULL)
        {
            flag=0;
            k=0;
            t=start->info[0];
            for(i=0;i<N;i++)
            {
                for(j=0;j<N;j++)
                {
                    if(t==matrix[i][j])
                    {
                        
                        r=graph(i,j,start->info,k,mat);
                    //printf("result=%d %d %d %d\n",i,j,k,r);
                        mat[i][j]=matrix[i][j];
                        //printf("\n");
                        //show(mat);
                        if(r==1)
                        {
                            flag=1;
                            break;
                        }
                    }
                }
                if(flag==1)
                break;
            }
            start=start->next;
        }
        return 0;
    }
    Dictionary(only few words):
    Car
    Card
    Carl
    Clap
    Ages

    Puzzle(matrix):
    A E P X
    I I A R
    L S D I
    D G C A

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    If you can't figure out what's going wrong here then you're in WAY over your head! (Pssst, you need to pass in the names of the dictionary and puzzle files on the command line. The dictionary words should be in uppercase (same case as the puzzle letters) and should contain some words that are actually in the puzzle.)

    BTW, the code you've procured is quite bad.

  3. #3
    Registered User
    Join Date
    Apr 2017
    Posts
    3
    Quote Originally Posted by algorism View Post
    If you can't figure out what's going wrong here then you're in WAY over your head! (Pssst, you need to pass in the names of the dictionary and puzzle files on the command line. The dictionary words should be in uppercase (same case as the puzzle letters) and should contain some words that are actually in the puzzle.)

    BTW, the code you've procured is quite bad.
    Exactly you're absolutely right. I am really over my head as Tuesday I have to do the presentation. I will change the dictionary file. But the thing is since the code is quite bad what should I do? Can you help me out?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    There is simply no time for you to be able to prepare for and pass your presentation if someone starts asking you detailed questions about that code.

    Unless
    - today, you study in detail this code and make lots of notes as to how you think it works.
    - tomorrow (Monday), first thing, you delete that code and try and write your OWN code from scratch, using your notes as a guide.
    If you apply yourself for a solid burn of undistracted study and coding, then you should be able to make a decent presentation.

    But if you're hoping to wing it with minimal effort, then you should fail - and deservedly so.

    Happy Easter, I hope you spend your last day productively.
    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.

  5. #5
    Registered User
    Join Date
    Apr 2017
    Posts
    3
    Quote Originally Posted by Salem View Post
    There is simply no time for you to be able to prepare for and pass your presentation if someone starts asking you detailed questions about that code.

    Unless
    - today, you study in detail this code and make lots of notes as to how you think it works.
    - tomorrow (Monday), first thing, you delete that code and try and write your OWN code from scratch, using your notes as a guide.
    If you apply yourself for a solid burn of undistracted study and coding, then you should be able to make a decent presentation.

    But if you're hoping to wing it with minimal effort, then you should fail - and deservedly so.

    Happy Easter, I hope you spend your last day productively.
    This is what I did, I made notes but the thing is What should i do so that the user will enter the words? And definitely not getting the file handling portion, I mean the puzzle and dictionary both are not opening.

  6. #6
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    The program you posted takes a dictionary and tries to find every word in it on the board. So it's kind of a Boggle solver, not a Boggle game for a human player.

    Is your program supposed to read in a pre-defined puzzle board or is it supposed to generate one?

    Have you been given a dictionary to use or do you have to aquire one yourself? A real dictionary would have tens of thousands of words.

    Your mainline might go something like this:
    Code:
    Read in the DICTIONARY
    Loop
        Generate the BOARD
        Clear the WORDS_PLAYED list
        Print the BOARD
        Start the TIMER
        While the TIMER hasn't run out
            Ask player for a WORD
            If WORD is in the DICTIONARY
                If WORD is not in the WORDS_PLAYED list
                    If WORD is on the BOARD
                        Increase SCORE
                        Add WORD to WORDS_PLAYED list
        Endwhile
    Until the player doesn't want to play again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting a simple game server for tile based game
    By cpu0 in forum Game Programming
    Replies: 1
    Last Post: 01-19-2017, 12:15 PM
  2. Programming Boggle in C++ using a time function
    By tnau in forum C++ Programming
    Replies: 1
    Last Post: 07-21-2015, 04:29 PM
  3. Boggle game.
    By Desolation in forum Game Programming
    Replies: 5
    Last Post: 08-03-2007, 01:52 AM
  4. Boggle board help
    By PuhFENDanT in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2003, 10:43 AM

Tags for this Thread