Packaging Of TK-MineSweeper


ResetGame Functions

We have our version of TK-MineSweeper, with all requirements of a basic mineSweeper game, ripe for being enhanced by Scout, DoNaLD, and extension to D TK-MineSweeper. However, as it stands, the current implementation is a touch messy to say the least. This is why a few improvements are in the bags.
 
First of all, we can define a triggered action which contains all of the neccessary initialisations to get TK-MineSweeper up and running. Then, when a game has been completed, this triggered action can be triggered again to reset the game. Even better, this triggered action uses random procedures to place mines in a random pattern. We even have the option of changing the probability that a mine may appear in a cell, through interaction with a probability variable.
 
The resetGame function derived for TK-MineSweeper is illustrated below :

  func resetGame {
    auto x;
    xDim is 4;
    yDim is 4;
    status is [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
    mines is [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    pos is 0;

    mineTemplate is ["?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?", "?"
      , "?", "?", "?"];

    won is 0;
    lost is 0;

    defuseList is [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

    defuse is 0;
    deselect is 0;
    prob is 0.28;

    for (x=1;x(32676*prob)) {
        mines[x]=0;
      } else {
        mines[x]=1;
      }
    }
    writeln("\n********************");
    writeln("** TK-MineSweeper **");
    writeln("********************");
    writeln("1999 - by jim\n);
    writeln(nMines, " mines to defuse\n");
    writeln("Use : pos is ;      - to select cell");
    writeln("      defuse is ;   - to defuse suspected mine cell");
    writeln("      deselect is ; - to deselect cell selected for defuse");
  }
This function assumes that a new variable, start has been created. This is a simple variable declaration thus :
  start is 0;
Now, we may define the triggered action which begins the TK-MineSweeper game. The name is, appropriately, TK_MineSweeper, and it appears as follows :
  func TK_MineSweeper : start {
    if (start==1) {
      resetGame();
    }
  }
These new functions take into consideration the criticism that the variable names in the developing model were too long, and so, the names have been changed as follows : The following pages deal with more advanced ideas for additions and modifications to this existing TK-MineSweeper implementation.
 
Clearly, due to the variable name changes, this final set of definitions are incompatible with the previous definitions. Download the up to date version of TK-MineSweeper.

 
 
Move to the thirteenth TK-MineSweeper page...
 
 
 

Updated Wednesday, January 6, 1999