The placement of mines should begin only after the first selection of any cell. Then the program should open several cells next to the first move, and only then you can start the game. Otherwise, the second move will be dangerous and unpredictable, and the game turns into primitive guessing instead of analysis.
In a correct algorithm, the initial field preparation time does not depend on the size of the matrix. It depends only on the number of mines.
Here is an example of generating mines and filling the matrix on the first move.
The field size is 20 (width) × 10 (heigt), the number of mines is N=25. The calculation time for the fx-9750GII(SH3) is t=2.6_sec.
20->W : 10->H // widht, height
{H W}->Dim Mat A : Fill(0, Mat A)
Mat A->Mat B : 3->R : 5->C // Mat A[3,5] for example, first step
1->Mat B[R,C] // R=3 and C=5 are not for mines
25->N : 0->S // number of mines and its counter
Do :
RanInt#(1,10)->A : RanInt#(1,20)->B
If Mat B[A,B]≠1 And Mat A[A,B]≠-1
Then Isz S : -1->Mat A[A,B] // put mine
For B-(B≠1)->K To B+(B≠W)
For A-(A≠1)->L To A+(A≠H)
Mat A[L,K]->D : Isz D : D->Mat A[L,K]
Next : Next : IfEnd
LpWhile S≠N : Mat A
// Mat A[Row,Col]=-1 it is a mine
// Mat A[R,C]=0...8 is number of mines around a cell
// Mat B[R,C]=0 is unopened cell without flag
// Mat B[R,C]>0 is a cell with the number of step
// Mat B[R,C]=-1 flag "?" is set to unopened cell
When the number of mines around an open cell is equal to the number of unopened cells around it, the program should automatically open and show the detected mines.
I think, 15 (width) × 10 (height) is the most suitable field size for playing on a calculator.
Here is an example of the design of the screen for the game.
GridOff : AxesOff : LabelOff : BG-None
ViewWindow 1,127,128,-63,-1,64
"###############"->Str 1 // 15 # symbols in String
// # is unopened cell
For 3->K To 57 Step 6
Text K,3,Str 1 : Next
Vertical 1 : Vertical 93
F-Line 2,-1,92,-1 : F-Line 2,-63,92,-63
Text 27,9,"▲" //image of mine, bold type up arrow from char/symbol menu
Text 27,21,"1 space" // clears left side of wide symbol
Text 27,21+1,"?" // temporary flag for an unopened cell
// 21+1 correction for the right placement
Text 27,33,"1 space"
Text 27,33+1,"2" // number of mines around an opened cell
Text 27,45,"1space"
Text 27,45+1,"□" // opened cell with no mines around
Text 27,57,"↓" // fatal step, down arrow
Text 3,99,"MINES" : Text 9,103,"15/1"
Text 21,99,"SCORE" : Text 27,107,"18"
Text 39,103,"END" : Text 45,107,"↓"
Also, the FX-9750GII allows you to make a game with dynamic interactive controls.
Edited by Hlib2, 04 April 2025 - 07:42 AM.