I have a college assignment and I am having segmentation fault with one of the functions. The assignment is about minesweeper game. Detailed description of the functions:random board ():
randomly positions num mines in the matrix, taking care not to place any mines in position i, j neither around position i, j. At the end of the call:
- each position of the matrix must be either UNKN FREE or UNKN MINE,
- there must be exactly num mines positions with UNKN MINE value,
- no position around i, j (included) must be UNKN MINE.
flag board ():
add a flag (flag) in position i, j:
- if position i, j has already been shown, it does nothing and returns 0,
- if position i, j is already "flagged", remove the flag (FLAG FREE becomes UNKN FREE and FLAG MINE becomes UNKN MINE) and returns -1,
- if position i, j is not "flagged" add a flag (UNKN FREE becomes FLAG FREE and UNKN MINE becomes FREE MINE) and returns 1.
display board ():
shows the content in position i, j
- if position i, j has already been shown or is "flagged" it does nothing and returns 0,
- if position i, j has not already been shown and contains a mine, place the constant MINE in i, j and returns -1,
- if position i, j has not already been shown and does not contain a mine, place in i, j the enumerative constant indicating the number of mines surrounding position i, j (ie C0, .. ., C8). If position i, j has no mines around it (i.e. it becomes C0) then all undiscovered positions around i, j are revealed. The same algorithm is repeated as long as positions marked with C0 are discovered. The function returns the total number of detected positions.
expand board ():
show the contents of the positions not yet unfolded around i, j. The behavior is exactly the same as for the display board (), return value included, but applied to all the cells not revealed around i, j. Cases where the function does nothing and returns 0:
- if the position i, j has not already been shown,
- if position i, j does not contain around a number of flag-gated cells equal to the number shown in i, j
display_ board() is having the segmentation error.
I am leaving below the code. Here is codeboard to check out the errors Codeboard * the IDE for the classroom
code.txt