Adding Coherancy To TK-MineSweeper


Loose Ends

We now have all of the essential aspects of mineSweeper in TK-MineSweeper. However, we have a number of loose ends to tie up. These are tackled in this part of the demonstration.

Winning (finally)

Since we have the means to win, we must now design some way of allowing TKeden to evaluate whether we've won or not. The criteria required to win can be shortlisted as follows :

Since we want this new function to test for a winning situation whenever we select another cell as a suspected mine, we can make the new function gameStatus to be a triggered action which is triggered whenever the number of mines in defuseList is modified.
 
Using this information, we can construct a function which carries out our requirements :
  func gameStatus : nDefused {
    auto x, temp;
    if (nDefused==nMines) {
      temp=0;
      for (x=1;x<=nCells;x++) {
        if (defuseList[x]!=mines[x]) {
          temp++;
        }
      }
      if (temp>0) {
        writeln("Mines Incorrectly Identified - Try Again");
        dispMF();
      } else {
        won=1;
      }
    }
  }

Wait - We Can't Deselect Incorrectly Selected Mines...

Not yet, anyway. Well, we need to be able to deselect incorrectly selected mines in order to win when we make bad choices. We can simply define a variable, say deselectDefuse to represent our choice for deselection thus :

  deselectDefuse is 0;
Again, as we do not wish any undesired side effects in the game, we set the initial value of deselectDefuse to 0.
 
Now, we require anotehr function which acts as a triggered action whenever the variable deselectDefuse is modified. This function is required to perform the following tests before it modifies the defuseList : These can be incorporated in deselectMine as follows :
  func deselectMine : deselectDefuse {
    if ((deselectDefuse>0)&&(deselectDefuse<=nCells)) {
      if (defuseList[deselectDefuse]==1) {
        defuseList[deselectDefuse]=0;
        mineTemplate[deselectDefuse]="?";
      } else {
        writeln("Cannnot Deselect Because Not Selected");
        dispMF();
      }
    }
  }
We have a complete version of TK-MineSweeper.
 
So, we may play the game now using the following interface : But wait. Those variable names are very long. Also, we could do with the game resetting after use. It would be nice if we had a different number of mines in random places. The final section concerning the basic model looks into all of these considerations.

 
 
Move to the twelvth TK-MineSweeper page...
 
 
 

Updated Wednesday, January 6, 1999