hello world. I dont can finish my project. can you solves the problems? I use code:blocks and every funktion and header is on a own file.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main(void);
void field(int paiOpen[][18], int iBig);
int summe(int iGroesse, int paiFeld[][18]);
int inputf(int *piFeld);
void randgen(int iGroesse, int iAllbombs, int paiFeld);
void end(int paiOpen[][18], int iBig);
void clear(int iFeld, int paiFeld[][18], int iSet);
int inputb(int iGroesse);



/*	logan denef
	IF1A Gruppe B
    06.06.10
    Meins Wieper*/

#include "header.h"

int main(void)
{
    int aiBombs[18][18], aiOffen[18][18], iGroesse, iGesbomben;

    srand(time(0));

    inputf(&iGroesse);

    printf("\niGroesse auf null\n");
    clear(iGroesse,aiBombs,0);
    printf("\naiOffen auf Null\n");
    clear(iGroesse,aiOffen,-1);

    iGesbomben=inputb(iGroesse);
    randgen(iGroesse, iGesbomben, aiBombs);
    field(aiOffen, iGroesse);
    getchar();
    return(0);
}


#include "header.h"

void clear(int iFeld, int paiFeld[][18], int iSet)

{
    int iX, iY;

    for(iX=0;iX<iFeld;iX++)
    {
        for(iY=0;iY<iFeld;iY++)
        {
            paiFeld[iX][iY]=iSet;
        }
    }

    printf("\n");
    printf("\n");


    printf("erste auf null gesetzt\n");
    for(iX=0;iX<iFeld;iX++)
    {
        for(iY=0;iY<iFeld;iY++)
        {
            printf("%d",paiFeld[iX][iY]);
        }
        printf("\n");
    }
    printf("\n");
}


#include "header.h"

void end(int paiOpen[][18], int iBig)

{
    int iX, iY, iL, iIndexx;
    char cAntwort;


        iBig++;
        for(iY=1;iY<iBig;iY++)
        {
            if(iY==1)
            {
                for(iIndexx=0;iIndexx<iBig;iIndexx++)
                {
                    if(iIndexx==0)
                    {
                        printf("   ");
                    }
                    else
                    {
                    printf(" %2d ", iIndexx);
                    }
                }
                printf("\n\n");
            }
                for(iX=1;iX<iBig;iX++)
                {
                    if(iX==1)
                    {
                        printf("   ");

                    }
                    printf("+---");
                    if(iX==iBig-1)
                    {
                        printf("+\n");
                        for(iL=1;iL<iBig;iL++)
                        {
                            if(iL==1)
                            {
                                printf("%2d ", iY);

                            }
                            switch(paiOpen[iX][iY])
                            {
                                case 0:
                                printf("|   ");
                                break;
                                case -9:
                                printf("| \01 ");
                                break;
                                case -1:
                                printf("| \02 ");
                                break;
                                default:
                                printf("| %d ", paiOpen[iX][iY]);
                                break;

                            }

                        }
                    printf("|\n");
                }
            }
        }
        printf("   +");
        for(iY=1;iY<iBig;iY++)
        {
            printf("---+");
        }


    iBig--;
    printf("moechten Sie nochmal spielen? (j/n)");
    scanf("%c",&cAntwort);
    fflush(stdin);
    if(cAntwort=='j')
    {
        main();
    }
    getchar();
}


#include "header.h"

void field(int paiOpen[][18], int iBig)

{
    int iX, iY, iL, iIndexx;


        iBig++;
        for(iY=1;iY<iBig;iY++)
        {
            if(iY==1)
            {
                for(iIndexx=0;iIndexx<iBig;iIndexx++)
                {
                    if(iIndexx==0)
                    {
                        printf("   ");
                    }
                    else
                    {
                    printf(" %2d ", iIndexx);
                    }
                }
                printf("\n\n");
            }
                for(iX=1;iX<iBig;iX++)
                {
                    if(iX==1)
                    {
                        printf("   ");

                    }
                    printf("+---");
                    if(iX==iBig-1)
                    {
                        printf("+\n");
                        for(iL=1;iL<iBig;iL++)
                        {
                            if(iL==1)
                            {
                                printf("%2d ", iY);

                            }
                            switch(paiOpen[iX][iY])
                            {
                                case -1:
                                iBig--;
                                printf("| %d ", paiOpen[iX][iY]);
                                break;
                                case -9:
                                printf("| \01 ");
                                end(paiOpen,iBig);
                                break;
                                default:
                                printf("| \02 ");
                                break;
                            }

                        }
                    printf("|\n");
                }
            }
        }
        printf("   +");
        for(iY=1;iY<iBig;iY++)
        {
            printf("---+");
        }
    printf("\n");

    iBig--;
}


#include "header.h"


int inputb(int iGroesse)

{
    int iBomb;

    do
    {
        printf("Wie viele Bomben moechten Sie verstecken?\n");
        scanf("%d",&iBomb);
        fflush(stdin);
        iBomb--;
        if(iBomb>=(iGroesse*iGroesse))
            {
                printf("Bitte waehlen Sie hoechstens soviele Bomben wie Felder da sind!\n");
                scanf("%d",&iBomb);
                fflush(stdin);
            }
    }
    while(iBomb>=(iGroesse*iGroesse));
    return(iBomb);
}


#include "header.h"

int inputf(int *piFeld)

{


    printf("wie gross soll das Feld werden?\n");
    scanf("%d",piFeld);
    fflush(stdin);

    return(*piFeld);
}


#include "header.h"

void randgen(int iGroesse, int iAllbombs,int paiFeld)
{
    int iBombs=0;
    int iZeile, iSpalte;


    int iX, iY;

    do
    {
        iZeile=rand()%iGroesse;
        iSpalte=rand()%iGroesse;

        if(paiFeld[iZeile][iSpalte]==0)
        {
            paiFeld[iZeile][iSpalte]=-9;
            iBombs++;
        }
    }
    while(iBombs<=iAllbombs);


    printf("bomben setzten\n\n");
    for(iX=0;iX<iGroesse;iX++)
    {
        for(iY=0;iY<iGroesse;iY++)
        {
            printf("%d",paiFeld[iY][iX]);
        }
        printf("\n");
    }
    printf("\n");
}



#include "header.h"

int summe(int iGroesse, int paiFeld[][18])

{
    int iX, iY, iL, iM, iSumme;

    printf("\n\nWelches Feld soll aufgedeckt werden?\nBitte geben Sie die Zeilennummer ein:");
    scanf("%d",&iX);
    fflush(stdin);
    printf("\nBitte geben Sie die Spaltennummer ein:");
    scanf("%d",&iY);
    fflush(stdin);
    iX--;
    iY--;
    if(*paiFeld[iX][iY]==-1)
    {
        printf("Dieses Feld ist bereits aufgedeckt");
    }
    if(*paiFeld[iX][iY]==-2)
    {
        end(&paiFeld, iGroesse);
    }
    iSumme=0;
    for(iL=-1;iL<2;iL++)
    {
        for(iM=-1;iM<2;iM++)
        {
            if((iX+iL>=0 || iY+iM>=0 || iGroesse>iX+iL || iGroesse>iY+iM) && iM!=0 && iL!=0)
                {
                    if (paiFeld[iX+iL][iY+iM]==-9)
                        {
                            iSumme++;
                            printf("test:%d",iSumme)
                        }
                }
        }
    }
    *paiFeld[iX][iY]=iSumme;
    getchar();
    return(iSumme);
}

its my first programm thats why i didnt comment it...
but if you have any question tell me it.

but if you have any question tell me it.

As a matter of fact I do. What's your original question?
And what's up with the atrocious explanation. I see the code is in another language (German, I guess.), please provide some comments in English.
Why are you including "header.h" multiple times. It is redundant & erroneous if "header.h" lacks code guards.

thank you to tell me what you need.
my question is only what I have to do to adjust the array?
sometimes i get a wrong value and sometimes i get an adress.
im not really an expert for arrays and pointer. i think i declared st wrong. perhaps can you explain me what i have to know and can you correct my mistake(s)
thx

Edited 6 Years Ago by god_like: forget a word

im not really an expert for arrays and pointer

How about a Tutorial

But still exactly what error are you getting?

P.S. Appreciate your effort.

updated_and_translated_minesweeper_with_more_comments.zip (43.1 KB, 0 views)

Edited 6 Years Ago by nbaztec: n/a

I just downloaded your file & there any many, it will be easier for me if you can just point out to me

a) What is your logic
b) What problem are you facing in that logic
c) Run-time and/or logical errors (if-any)

I just downloaded your file & there any many, it will be easier for me if you can just point out to me

a) What is your logic
b) What problem are you facing in that logic
c) Run-time and/or logical errors (if-any)

a) its a simple minesweeper game. I used only one array for the whole game. i hope you read the comments in it. you can create a square and set the numbers of bombs you want. than you have to try your luck and your skills to unhide the whole square without revealing a bomb. the array i unhide is only a help to find errors. it will be hide when it works fine.
you choose a field. it will be check if its already revealed. it will be check if its contains a bomb. if it contains no bombs, he counts the bombs arround it....

now, it runs. my problem was that it doesnt works. you can test is if you want. perhaps i can optimize it because normally at minesweeper you can choose a field to reveal and its unhide all fields with zero bombs surrounding it and the fields too that show the numbers of bombs. if you doesnt know how it works and how it have to work compaire my version with the windows version.

my problem was that it doesnt works

Which part:
detecting bombs, Making grid, etc.
P.S. Yes I played it & it indeed doesn't work.

I see these problems with your program:

1) non-bomb squares adjacent to your chosen square, don't "avalanche" open.

2) you can't mark a square as a bomb, like you can in Minesweeper

3) the game doesn't end when the last free square has been chosen. It should be congratulating me for winning the game.

4) there is no way to quit the game, either at the main menu, or while working with the playing grid.


To fix the ending, just count up the number of free squares remaining, and when the count reaches zero, the player is declared the winner and the program should return to the main menu. Also, set up a < Q to Quit> message and logic.

The "avalanche" function will be the most difficult fix, but give it a try. Come back if you get stuck.

I see these problems with your program:
1) non-bomb squares adjacent to your chosen square, don't "avalanche" open.
2) you can't mark a square as a bomb, like you can in Minesweeper
3) the game doesn't end when the last free square has been chosen. It should be congratulating me for winning the game.
4) there is no way to quit the game, either at the main menu, or while working with the playing grid.

1) have you an idea of the logic?
2) i could make it but i found this function stupid :)
3) i fix this problem i think. it will be nice if you could test it
4) how do you mean it? you can quit the game after win/loose. and if you open it you probably doesnt want to close it direcly?!

also test it to find mistakes please

Check out "floodfill" and "Minesweeper" (the game),on Wikipedia. One of them should have an example of how it works.

A bomb detection game with no bombs being represented?? Say it ain't so! ;)

I will test it. I'm also looking around for my old minesweeper program, but it may have been lost some years in the past.

You always need to have the user be able to quit the game - MAYBE even save the current game; but definitely to quit it.

Edited 6 Years Ago by Adak: n/a

I couldn't find my old minesweeper game, so I started a new one. I found this description of the Cascade algorithm helpful, so I used it to help with that logic. I have only tested this function a few times, so I can't say it's OK, just yet.

/* 
"
Another interesting detail is the iterative nature of the cascade algorithm. 
It is clear that the queue data-structure can be replaced with any container 
data-structure. A stack is an obvious choice. Which begs the question: why 
the implementors did not use recursion to implement the algorithm? 
The use of recursion in this case would have considerably simplified the 
algorithm as it would obviate the need for the queue data-structure. The 
recursive algorithm would work as follows:

   1. If current square is a mine gameover, otherwise uncover square
   2. Count mines adjacent to current square
   3. If adjacent mine count is zero, uncover all adjacent covered squares 
      and make a recursive call for every one of them (steps 2-3)
"
*/
void cascade(int row, int col) {
  int i, mines, r=row, c=col;

  if(grid[row][col].n || grid[row][col].mines) 
    return;
  else {
    if(grid[r-1][c].n==9) grid[r][c].mines++;       //12 o'clock
    if(grid[r-1][c+1].n==9) grid[r][c].mines++;     //1:30 o'clock
    if(grid[r][c+1].n==9) grid[r][c].mines++;       //3 o'clock

    if(grid[r+1][c+1].n==9) grid[r][c].mines++;     //4:30 o'clock
    if(grid[r+1][c].n==9) grid[r][c].mines++;       //6 o'clock
    if(grid[r+1][c-1].n==9) grid[r][c].mines++;     //7:30 o'clock

    if(grid[r][c-1].n==9) grid[r][c].mines++;       //9 o'clock
    if(grid[r-1][c-1].n==9) grid[r][c].mines++;     //10:30 o'clock
    
  
    if(grid[r][c].mines==0) {
      grid[r][c].n=1;  //open this square
      //recursive call for all adjacent squares
      cascade(r-1, c);    //12 o'clock 
      cascade(r-1, c+1);  //1:30 o'clock 
      cascade(r, c+1);    //3 o'clock 
      cascade(r+1, c+1);  //4:30 o'clock 
      cascade(r+1, c);    //6 o'clock 
      cascade(r+1, c-1);  //7:30 o'clock 
      cascade(r, c-1);    //9 o'clock 
      cascade(r-1, c-1);  //10:30 o'clock 
    }
  }
  return; 
}

The grid[][] is the playing board. Every element or square, is a struct with two int's:

int n -- the value of the square
int mines -- the number of mines that are adjacent to the square.

So grid[1][1].n is the value of the square at grid[1][1].

Around the grid on all four sides, I put one extra row or column, and gave it a value of 10. That won't get shown in the game to the player, but helps a lot with keeping the index value, inside the square of the playing area. (As you can see above).

I thought making that number of mines surrounding it, part of a struct, would work out well - so far it has.

I'll test your latest code, in just a few minutes. If you have any questions or see a problem with the Cascade function above, let me know.

Edit: Looking better!

Edited 6 Years Ago by Adak: n/a

hi adak
i dont understand who this function have to work. the time i have to finish it is out, but if you want you can explain it. im curious to know it.

The Cascade feature was the most noticeable feature of Minesweeper. You clicked on one square, and suddenly 5 or 10 or 20 squares were uncovered in front of your eyes, as if by magic.

Since it never uncovers a square with a mine, it added a lot of zip to the game - the game went by faster, especially when playing with a larger number of squares. The pseudo code in green, gave about the clearest description of the logic for the Cascade. I used it to describe the Cascade function, right in my program. Took me two tries to get the logic right, though.

If you have already turned in your program, I believe we can definitely mark this thread as "solved". ;)

I have not yet written the code to mark a mine. That's next.

Good luck with your studies!

This question has already been answered. Start a new discussion instead.