Thread: Recreating Minesweeper.

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    45

    Recreating Minesweeper.

    I'm in the process of recreating minesweeper in C. This is what I have so far, it's not complete i'm still testing it out. I am haveing a big problem with the floodfill which is ment to turn all the corrosponding cells that should be revealed to 1. Currently I have it displaying the bombs map then the hidden cells so I can see how it's working till I finish the program. Can you help me out with the errors that I am getting.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    struct ms{
    	int bombs;
    	int uncovered;
    	int printvalue;
    } field[9][9];
    
    int floodfill(struct ms field[][], int, int);
    
    
    int main (void)
    {
    int b,i,o;
    
    	srand(time(NULL));
    	for(b=0;b<10;b++){
    		i=rand()%9;
    		o=rand()%9;
    		if (field[i][o].bombs == 42)b--;
    		field[i][o].bombs = 42;
    			}
    
    	for (i=0;i<9;i++){
    		for(o=0;o<9;o++){
    			if (field[i][o].bombs != 42){
    				field[i][o].bombs = 48;}}
    	}
    
    	/*outer bonds, courners, 00, 80, 08, 88*/
    	if (field[0][0].bombs == 42){if (field[1][0].bombs != 42)field[1][0].bombs++; if (field[1][1].bombs != 42)field[1][1].bombs++; if (field[0][1].bombs != 42)field[0][1].bombs++;}
    	if (field[0][8].bombs == 42){if (field[0][7].bombs != 42)field[0][7].bombs++; if (field[1][7].bombs != 42)field[1][7].bombs++; if (field[1][8].bombs != 42)field[1][8].bombs++;}
    	if (field[8][0].bombs == 42){if (field[7][0].bombs != 42)field[7][0].bombs++; if (field[7][1].bombs != 42)field[7][1].bombs++; if (field[8][1].bombs != 42)field[8][1].bombs++;}
    	if (field[8][8].bombs == 42){if (field[7][7].bombs != 42)field[7][7].bombs++; if (field[7][8].bombs != 42)field[7][8].bombs++; if (field[8][7].bombs != 42)field[8][7].bombs++;}
    	
    	/*Sides left*/
    	for(i=1;i<8;i++){
    			if (field[i][0].bombs == 42){
    				if (field[i-1][0].bombs != 42)field[i-1][0].bombs++; 
    				if (field[i+1][0].bombs != 42)field[i+1][0].bombs++; 
    				if (field[i][1].bombs != 42)field[i][1].bombs++;
    				if (field[i+1][1].bombs != 42)field[i+1][1].bombs++; 
    				if (field[i-1][1].bombs != 42)field[i-1][1].bombs++;
    			}
    	}
    	/*Side Right*/
    	for(i=1;i<8;i++){
    		if (field[i][8].bombs == 42){
    			if (field[i-1][8].bombs != 42)field[i-1][8].bombs++; 
    			if (field[i+1][8].bombs != 42)field[i+1][8].bombs++; 
    			if (field[i][7].bombs != 42)field[i][7].bombs++;
    			if (field[i+1][7].bombs != 42)field[i+1][7].bombs++; 
    			if (field[i-1][7].bombs != 42)field[i-1][7].bombs++;
    		}
    	}
    	/*Top wall*/
    	for(o=1;o<8;o++){
    		if (field[0][o].bombs == 42){
    			if (field[0][o-1].bombs != 42)field[0][o-1].bombs++; 
    			if (field[0][o+1].bombs != 42)field[0][o+1].bombs++; 
    			if (field[1][o].bombs != 42)field[1][o].bombs++;
    			if (field[1][o-1].bombs != 42)field[1][o-1].bombs++; 
    			if (field[1][o+1].bombs != 42)field[1][o+1].bombs++;
    		}
    	}
    	/*Bottom wall*/
    	for(o=1;o<8;o++){
    		if (field[8][o].bombs == 42){
    			if (field[8][o-1].bombs != 42)field[8][o-1].bombs++; 
    			if (field[8][o+1].bombs != 42)field[8][o+1].bombs++; 
    			if (field[7][o].bombs != 42)field[7][o].bombs++;
    			if (field[7][o-1].bombs != 42)field[7][o-1].bombs++; 
    			if (field[7][o+1].bombs != 42)field[7][o+1].bombs++;
    		}
    	}
    	/*for i = 1-8 and o = 1-8, inner bonds*/
    	for (i=1;i<8;i++){
    		for (o=1;o<8;o++){
    			if (field[i][o].bombs == 42){
    					if (field[i-1][o].bombs != 42)field[i-1][o].bombs++;
    					if (field[i+1][o].bombs != 42)field[i+1][o].bombs++;
    					if (field[i-1][o+1].bombs != 42)field[i-1][o+1].bombs++;
    					if (field[i][o+1].bombs != 42)field[i][o+1].bombs++;
    					if (field[i+1][o+1].bombs != 42)field[i+1][o+1].bombs++;
    					if (field[i-1][o-1].bombs != 42)field[i-1][o-1].bombs++;
    					if (field[i][o-1].bombs != 42)field[i][o-1].bombs++;
    					if (field[i+1][o-1].bombs != 42)field[i+1][o-1].bombs++;
    				}
    			}
    		}
    
    printf("\n\n\t*******************\n\t*   MineSweeper   *\n\t*******************\n"); 
    printf("\n\t  0 1 2 3 4 5 6 7 8\n\t  -----------------\n");
    	for(i=0;i<9;i++)printf("\t%d|%c %c %c %c %c %c %c %c %c|\n", i, field[i][0].bombs,field[i][1].bombs,field[i][2].bombs,field[i][3].bombs,field[i][4].bombs,field[i][5].bombs,field[i][6].bombs,field[i][7].bombs,field[i][8].bombs); 
    printf("\t  -----------------");
    printf("\n\nEnter Coordinates Values: ");
    scanf("%d %d", &i, &o);
    field[i][o].uncovered = 1;
    
    floodfill(field, i, o);
    
    if (field[i][o].bombs == 42){printf("\nBOOM!!! Game Over, you hit a bomb.\n"); return 0;}
    	
    
    
    /*compaire*/
    for(i=0;i<9;i++){
    	for(o=0;o<9;o++){
    		if (field[i][o].uncovered == 1)field[i][o].printvalue = field[i][o].bombs;
    		if(field[i][o].uncovered== 0)field[i][o].printvalue = 45;
    		}
    	}
    
    printf("\n\t  0 1 2 3 4 5 6 7 8\n\t  -----------------\n");
    	for(i=0;i<9;i++)printf("\t%d|%c %c %c %c %c %c %c %c %c|\n", i, field[i][0].printvalue,field[i][1].printvalue,field[i][2].printvalue,field[i][3].printvalue,field[i][4].printvalue,field[i][5].printvalue,field[i][6].printvalue,field[i][7].printvalue,field[i][8].printvalue); 
    printf("\t  -----------------");
    
    return 0;
    	
    	}
    
    
    
    int floodfill(struct ms field[][], int i, int o){
    		if((i<0) || (o<0) || (i>8) || (o>8)){
    				return 0;
    			}
    		if(field[i][o].bombs = 42){
     				return 0;
    			}
    			
    	field[i][o].uncovered = 1;
     	
    	floodFill(field, i-1, o);
     	floodFill(field, i, o-1);
    	floodFill(field, i, o+1);
     	floodFill(field, i+1, o);
    				return 0;
    			}
    Here are the errors that I am recieving:
    Code:
    --------------------Configuration: ms2 - Win32 Debug--------------------
    Compiling...
    ms2.c
    C:\programming\ms2.c(11) : error C2087: '<Unknown>' : missing subscript
    C:\programming\ms2.c(101) : warning C4048: different array subscripts : 'struct ms (*)[1]' and 'struct ms [9][9]'
    C:\programming\ms2.c(101) : warning C4024: 'floodfill' : different types for formal and actual parameter 1
    C:\programming\ms2.c(124) : error C2087: '<Unknown>' : missing subscript
    C:\programming\ms2.c(134) : warning C4013: 'floodFill' undefined; assuming extern returning int
    Error executing cl.exe.
    
    ms2.exe - 2 error(s), 3 warning(s)

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    int floodfill(struct ms field[][], int i, int o)
    Is equal to:
    floodFill(field, i-1, o);
    Last edited by Vber; 02-09-2003 at 04:15 PM.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    45
    I fixed the type-o of "floodFill" but I am still recieving these erros...

    C:\programming\ms2.c(11) : error C2087: '<Unknown>' : missing subscript
    C:\programming\ms2.c(101) : warning C4048: different array subscripts : 'struct ms (*)[1]' and 'struct ms [9][9]'
    C:\programming\ms2.c(101) : warning C4024: 'floodfill' : different types for formal and actual parameter 1
    C:\programming\ms2.c(124) : error C2087: '<Unknown>' : missing subscript


    which deals with me passing my structure. they are the line that declares the function, the line that calls the function and the line where the function begins. Any idea what i'm doing wrong?

  4. #4
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    You should pass your struct like this:
    Code:
    int floodFill(struct ms field[][9], int, int);
    Fix your code, and check if you still get errors

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    45
    alright it works now... thanks.

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    Trying to fix

    I was also trying to fix this coding but i still ended up with 2 errors, could somebody please help me find these errors
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    
    struct ms{
    	int bombs;
    	int uncovered;
    	int printvalue;
    } 
    field[9][9];
    
    int floodfill(struct ms field[][9], int, int);
    
    
    
    int main (void)
    {
    int b,i,o;
    
    	srand(time(NULL));
    	for(b=0;b<10;b++){
    		i=rand()%9;
    		o=rand()%9;
    		if (field[i][o].bombs == 42)b--;
    		field[i][o].bombs = 42;
    			}
    	for (i=0;i<9;i++){
    		for(o=0;o<9;o++){
    			if (field[i][o].bombs != 42){
    				field[i][o].bombs = 48;}}
    	}
    
    	/*outer bonds, courners, 00, 80, 08, 88*/
    	if (field[0][0].bombs == 42){if (field[1][0].bombs != 42)field[1][0].bombs++; if (field[1][1].bombs != 42)field[1][1].bombs++; if (field[0][1].bombs != 42)field[0][1].bombs++;}
    	if (field[0][8].bombs == 42){if (field[0][7].bombs != 42)field[0][7].bombs++; if (field[1][7].bombs != 42)field[1][7].bombs++; if (field[1][8].bombs != 42)field[1][8].bombs++;}
    	if (field[8][0].bombs == 42){if (field[7][0].bombs != 42)field[7][0].bombs++; if (field[7][1].bombs != 42)field[7][1].bombs++; if (field[8][1].bombs != 42)field[8][1].bombs++;}
    	if (field[8][8].bombs == 42){if (field[7][7].bombs != 42)field[7][7].bombs++; if (field[7][8].bombs != 42)field[7][8].bombs++; if (field[8][7].bombs != 42)field[8][7].bombs++;}
    	
    	/*Sides left*/
    	for(i=1;i<8;i++){
    			if (field[i][0].bombs == 42){
    				if (field[i-1][0].bombs != 42)field[i-1][0].bombs++; 
    				if (field[i+1][0].bombs != 42)field[i+1][0].bombs++; 
    				if (field[i][1].bombs != 42)field[i][1].bombs++;
    				if (field[i+1][1].bombs != 42)field[i+1][1].bombs++; 
    				if (field[i-1][1].bombs != 42)field[i-1][1].bombs++;
    			}
    	}
    	/*Side Right*/
    	for(i=1;i<8;i++){
    		if (field[i][8].bombs == 42){
    			if (field[i-1][8].bombs != 42)field[i-1][8].bombs++; 
    			if (field[i+1][8].bombs != 42)field[i+1][8].bombs++; 
    			if (field[i][7].bombs != 42)field[i][7].bombs++;
    			if (field[i+1][7].bombs != 42)field[i+1][7].bombs++; 
    			if (field[i-1][7].bombs != 42)field[i-1][7].bombs++;
    		}
    	}
    	/*Top wall*/
    	for(o=1;o<8;o++){
    		if (field[0][o].bombs == 42){
    			if (field[0][o-1].bombs != 42)field[0][o-1].bombs++; 
    			if (field[0][o+1].bombs != 42)field[0][o+1].bombs++; 
    			if (field[1][o].bombs != 42)field[1][o].bombs++;
    			if (field[1][o-1].bombs != 42)field[1][o-1].bombs++; 
    			if (field[1][o+1].bombs != 42)field[1][o+1].bombs++;
    		}
    	}
    	/*Bottom wall*/
    	for(o=1;o<8;o++){
    		if (field[8][o].bombs == 42){
    			if (field[8][o-1].bombs != 42)field[8][o-1].bombs++; 
    			if (field[8][o+1].bombs != 42)field[8][o+1].bombs++; 
    			if (field[7][o].bombs != 42)field[7][o].bombs++;
    			if (field[7][o-1].bombs != 42)field[7][o-1].bombs++; 
    			if (field[7][o+1].bombs != 42)field[7][o+1].bombs++;
    		}
    	}
    	/*for i = 1-8 and o = 1-8, inner bonds*/
    	for (i=1;i<8;i++){
    		for (o=1;o<8;o++){
    			if (field[i][o].bombs == 42){
    					if (field[i-1][o].bombs != 42)field[i-1][o].bombs++;
    					if (field[i+1][o].bombs != 42)field[i+1][o].bombs++;
    					if (field[i-1][o+1].bombs != 42)field[i-1][o+1].bombs++;
    					if (field[i][o+1].bombs != 42)field[i][o+1].bombs++;
    					if (field[i+1][o+1].bombs != 42)field[i+1][o+1].bombs++;
    					if (field[i-1][o-1].bombs != 42)field[i-1][o-1].bombs++;
    					if (field[i][o-1].bombs != 42)field[i][o-1].bombs++;
    					if (field[i+1][o-1].bombs != 42)field[i+1][o-1].bombs++;
    				}
    			}
    		}
    
    printf("\n\n\t*******************\n\t*   MineSweeper   *\n\t*******************\n"); 
    printf("\n\t  0 1 2 3 4 5 6 7 8\n\t  -----------------\n");
    	for(i=0;i<9;i++)printf("\t%d|%c %c %c %c %c %c %c %c %c|\n", i, field[i][0].bombs,field[i][1].bombs,field[i][2].bombs,field[i][3].bombs,field[i][4].bombs,field[i][5].bombs,field[i][6].bombs,field[i][7].bombs,field[i][8].bombs); 
    printf("\t  -----------------");
    printf("\n\nEnter Coordinates Values: ");
    scanf("%d %d", &i, &o);
    field[i][o].uncovered = 1;
    
    floodfill(field, i, o);
    
    if (field[i][o].bombs == 42){printf("\nBOOM!!! Game Over, you hit a bomb.\n"); return 0;}
    	
    
    
    /*compaire*/
    for(i=0;i<9;i++){
    	for(o=0;o<9;o++){
    		if (field[i][o].uncovered == 1)field[i][o].printvalue = field[i][o].bombs;
    		if(field[i][o].uncovered== 0)field[i][o].printvalue = 45;
    		}
    	}
    
    printf("\n\t  0 1 2 3 4 5 6 7 8\n\t  -----------------\n");
    	for(i=0;i<9;i++)printf("\t%d|%c %c %c %c %c %c %c %c %c|\n", i, field[i][0].printvalue,field[i][1].printvalue,field[i][2].printvalue,field[i][3].printvalue,field[i][4].printvalue,field[i][5].printvalue,field[i][6].printvalue,field[i][7].printvalue,field[i][8].printvalue); 
    printf("\t  -----------------");
    
    return 0;
    	
    	}
    
    
    int floodFill(struct ms field[][9], int, int);
    
    {
    		if((i<0) || (o<0) || (i>8) || (o>8)){
    				return 0;
    			}
    		if(field[i][o].bombs = 42){
     				return 0;
    			}
    			
    	field[i][o].uncovered = 1;
     	
    	floodFill(field, i-1, o);
     	floodFill(field, i, o-1);
    	floodFill(field, i, o+1);
     	floodFill(field, i+1, o);
    	return 0;
    }
    these are the errors i had
    C:\Windows\Desktop\testing2.c(129) : error C2449: found '{' at file scope (missing function header?)
    C:\Windows\Desktop\testing2.c(144) : error C2059: syntax error : '}'
    Error executing cl.exe.

    testing2.obj - 2 error(s), 0 warning(s)

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>int floodFill(struct ms field[][9], int, int);
    The function header requires you to name the 2 int variables, and loose the semi-colon. This is OK for a prototype though, so make sure you fix the correct line.

    >>if (field[i][o].bombs = 42)
    Possible incorrect assignment. Use == for comparison.

    >>floodfill(field, i, o);
    The function name is spelt differently. Remember, C is case sensative, so floodfill is not the same as floodFill.

    There might be more errors, see how you go.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    another question...

    Hammer i fixed the typos and == comparing problem... then i took the semi colon of "int floodFill(struct ms field[][9], int, int);"

    the problem that im still having is when you said "The function header requires you to name the 2 int variables" could you please show me an example of how to fix that.

    and the errors im getting now after i made the changes are these


    C:\Windows\Desktop\testing2.c(130) : error C2055: expected formal parameter list, not a type list
    C:\Windows\Desktop\testing2.c(131) : error C2065: 'i' : undeclared identifier
    C:\Windows\Desktop\testing2.c(131) : error C2065: 'o' : undeclared identifier

    thanks again

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>int floodFill(struct ms field[][9], int, int);
    should be something like:
    >>int floodFill(struct ms field[][9], int i, int o)
    Without fully understanding your code, I don't know what names to give the 2 int parameters, but i and o seem like a good choice, as you haven't defined them anywhere else in that function, hence the error messages from your compiler.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  10. #10
    Registered User
    Join Date
    Feb 2003
    Posts
    5
    Thanks again hammer, ok after i put that in it will now run for me with no errors. The problem im having now is it is never covering the squares it is showing all of the spots uncovered. If you or anybody else would please see which step im missing in order to mask the spaces so it is like minesweeper i would be very happy. Thanks again everybody and I am posting the updated code below.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    
    struct ms{
    	int bombs;
    	int uncovered;
    	int printvalue;
    } 
    field[9][9];
    
    int floodfill(struct ms field[][9], int, int);
    
    
    int main (void)
    {
    int b,i,o;
    
    	srand(time(NULL));
    	for(b=0;b<10;b++){
    		i=rand()%9;
    		o=rand()%9;
    		if (field[i][o].bombs == 42)b--;
    		field[i][o].bombs = 42;
    			}
    	for (i=0;i<9;i++){
    		for(o=0;o<9;o++){
    			if (field[i][o].bombs != 42){
    				field[i][o].bombs = 48;}}
    	}
    
    	/*outer bonds, courners, 00, 80, 08, 88*/
    	if (field[0][0].bombs == 42){if (field[1][0].bombs != 42)field[1][0].bombs++; if (field[1][1].bombs != 42)field[1][1].bombs++; if (field[0][1].bombs != 42)field[0][1].bombs++;}
    	if (field[0][8].bombs == 42){if (field[0][7].bombs != 42)field[0][7].bombs++; if (field[1][7].bombs != 42)field[1][7].bombs++; if (field[1][8].bombs != 42)field[1][8].bombs++;}
    	if (field[8][0].bombs == 42){if (field[7][0].bombs != 42)field[7][0].bombs++; if (field[7][1].bombs != 42)field[7][1].bombs++; if (field[8][1].bombs != 42)field[8][1].bombs++;}
    	if (field[8][8].bombs == 42){if (field[7][7].bombs != 42)field[7][7].bombs++; if (field[7][8].bombs != 42)field[7][8].bombs++; if (field[8][7].bombs != 42)field[8][7].bombs++;}
    	
    	/*Sides left*/
    	for(i=1;i<8;i++){
    			if (field[i][0].bombs == 42){
    				if (field[i-1][0].bombs != 42)field[i-1][0].bombs++; 
    				if (field[i+1][0].bombs != 42)field[i+1][0].bombs++; 
    				if (field[i][1].bombs != 42)field[i][1].bombs++;
    				if (field[i+1][1].bombs != 42)field[i+1][1].bombs++; 
    				if (field[i-1][1].bombs != 42)field[i-1][1].bombs++;
    			}
    	}
    	/*Side Right*/
    	for(i=1;i<8;i++){
    		if (field[i][8].bombs == 42){
    			if (field[i-1][8].bombs != 42)field[i-1][8].bombs++; 
    			if (field[i+1][8].bombs != 42)field[i+1][8].bombs++; 
    			if (field[i][7].bombs != 42)field[i][7].bombs++;
    			if (field[i+1][7].bombs != 42)field[i+1][7].bombs++; 
    			if (field[i-1][7].bombs != 42)field[i-1][7].bombs++;
    		}
    	}
    	/*Top wall*/
    	for(o=1;o<8;o++){
    		if (field[0][o].bombs == 42){
    			if (field[0][o-1].bombs != 42)field[0][o-1].bombs++; 
    			if (field[0][o+1].bombs != 42)field[0][o+1].bombs++; 
    			if (field[1][o].bombs != 42)field[1][o].bombs++;
    			if (field[1][o-1].bombs != 42)field[1][o-1].bombs++; 
    			if (field[1][o+1].bombs != 42)field[1][o+1].bombs++;
    		}
    	}
    	/*Bottom wall*/
    	for(o=1;o<8;o++){
    		if (field[8][o].bombs == 42){
    			if (field[8][o-1].bombs != 42)field[8][o-1].bombs++; 
    			if (field[8][o+1].bombs != 42)field[8][o+1].bombs++; 
    			if (field[7][o].bombs != 42)field[7][o].bombs++;
    			if (field[7][o-1].bombs != 42)field[7][o-1].bombs++; 
    			if (field[7][o+1].bombs != 42)field[7][o+1].bombs++;
    		}
    	}
    	/*for i = 1-8 and o = 1-8, inner bonds*/
    	for (i=1;i<8;i++){
    		for (o=1;o<8;o++){
    			if (field[i][o].bombs == 42){
    					if (field[i-1][o].bombs != 42)field[i-1][o].bombs++;
    					if (field[i+1][o].bombs != 42)field[i+1][o].bombs++;
    					if (field[i-1][o+1].bombs != 42)field[i-1][o+1].bombs++;
    					if (field[i][o+1].bombs != 42)field[i][o+1].bombs++;
    					if (field[i+1][o+1].bombs != 42)field[i+1][o+1].bombs++;
    					if (field[i-1][o-1].bombs != 42)field[i-1][o-1].bombs++;
    					if (field[i][o-1].bombs != 42)field[i][o-1].bombs++;
    					if (field[i+1][o-1].bombs != 42)field[i+1][o-1].bombs++;
    				}
    			}
    		}
    
    printf("\n\n\t*******************\n\t*   MineSweeper   *\n\t*******************\n"); 
    printf("\n\t  0 1 2 3 4 5 6 7 8\n\t  -----------------\n");
    	for(i=0;i<9;i++)printf("\t%d|%c %c %c %c %c %c %c %c %c|\n", i, field[i][0].bombs,field[i][1].bombs,field[i][2].bombs,field[i][3].bombs,field[i][4].bombs,field[i][5].bombs,field[i][6].bombs,field[i][7].bombs,field[i][8].bombs); 
    printf("\t  -----------------");
    printf("\n\nEnter Coordinates Values: ");
    scanf("%d %d", &i, &o);
    field[i][o].uncovered = 1;
    
    floodfill(field, i, o);
    
    if (field[i][o].bombs == 42){printf("\nBOOM!!! Game Over, you hit a bomb.\n"); return 0;}
    	
    
    
    /*compaire*/
    for(i=0;i<9;i++){
    	for(o=0;o<9;o++){
    		if (field[i][o].uncovered == 1)field[i][o].printvalue = field[i][o].bombs;
    		if(field[i][o].uncovered== 0)field[i][o].printvalue = 45;
    		}
    	}
    
    printf("\n\t  0 1 2 3 4 5 6 7 8\n\t  -----------------\n");
    	for(i=0;i<9;i++)printf("\t%d|%c %c %c %c %c %c %c %c %c|\n", i, field[i][0].printvalue,field[i][1].printvalue,field[i][2].printvalue,field[i][3].printvalue,field[i][4].printvalue,field[i][5].printvalue,field[i][6].printvalue,field[i][7].printvalue,field[i][8].printvalue); 
    printf("\t  -----------------");
    
    return 0;
    	
    	}
    
    
    int floodfill(struct ms field[][9], int i, int o)
    
    
    {
    		if((i<0) || (o<0) || (i>8) || (o>8)){
    				return 0;
    			}
    		if(field[i][o].bombs == 42){
     				return 0;
    			}
    			
    	field[i][o].uncovered = 1;
     	
    	floodfill(field, i-1, o);
     	floodfill(field, i, o-1);
    	floodfill(field, i, o+1);
     	floodfill(field, i+1, o);
    	return 0;
    }

  11. #11
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    In main(), just before you ask the user to input the coords, you print the board in open text. That'll be one problem.

    I don't *think* the floodFill() works right, but I'll leave that to you for now...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  12. #12
    Registered User
    Join Date
    Jan 2003
    Posts
    45
    I got it all workin... thanks

  13. #13
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by j0hnb
    I got it all workin... thanks
    I know, we're now helping shwang.... and I can't be bothered to split the thread
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  14. #14
    Registered User
    Join Date
    Feb 2003
    Posts
    5

    J0hnb

    Could you please post the working code for me? Thanks

  15. #15
    Registered User
    Join Date
    Feb 2003
    Posts
    5
    I guess he isn't going to post the fixed code, if anybody else has any suggestions on what i can do to fix the above code please let me know. thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. minesweeper
    By mark69 in forum C Programming
    Replies: 2
    Last Post: 11-26-2007, 10:28 AM
  2. What's the best way to draw a minesweeper field
    By Nazgulled in forum C Programming
    Replies: 1
    Last Post: 05-08-2007, 01:24 PM
  3. AI Contest - Minesweeper
    By Darryl in forum Contests Board
    Replies: 93
    Last Post: 04-24-2006, 05:48 PM
  4. Minesweeper errors...
    By j0hnb in forum C Programming
    Replies: 0
    Last Post: 02-10-2003, 01:36 PM
  5. minesweeper problem
    By adamrobbie in forum C Programming
    Replies: 2
    Last Post: 10-14-2002, 08:03 PM