More Complex Aspects Of The Game


Defusing Mines & Winning

It's high time that the player be given an advantage in TK-MineSweeper. For almost ten pages, the player had to lose all of the time, but now, here's a changce to win.
 
With all important play aspects in place, the time has come to allow the player to defuse mines in cells suspected to contain mines.
 
So, how do we go about this task ?
 
First of all, we are taking the list approach again to tackle this problem. Currently, lists define the properties a) hidden/uncovered, b) mine/no mine and c) values of cells. Now, we can create another list which determines whether or not a particular cell has been selected as a suspected mine or not. Again, if cell 9 is suspected as containing a mine, and is chosen, then element 9 of the new list will be set to 1 to represent the notion I think that cell 9 contains a mine.
 
As default, however, all values in what is to be called the defuseList, are set to 0 to represent that they are not suspected as containing mines.
 
We can define defuseList as follows :

  defuseList is [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
We must know how many mines have been selected for defusing, since the mineSweeper hero is limited to selecting only the same number of cells as suspected mines as there are actual mines. Hence, we may define a variable, nDefused, which contains the number of suspected mines, as follows :
  nDefused is defusedList[1] + defusedList[2] + defusedList[3] + defusedList[4]     + defusedList[5] + defusedList[6] + defusedList[7] + defusedList[8] + defusedList[9]        + defusedList[10] + defusedList[11] + defusedList[12] + defusedList[13]
    + defusedList[14] +defusedList[15] +defusedList[16];
With these in place, we need some sort of user interface such that a user can select a suspected cell as a defuse cell. Similar to the use of currentPos for selecting of a cell to 'try', we can define a variable, currentDefused, which contains a cell reference to a cell suspected of being a mine. This is simply included as follows :
  currentDefused is 0;
Again, we set the initial value to 0, otherwise, we may select a cell for defuse before the game has even been started.
 
We now need a function which can be used to perform the required actions to allow a cell suspected of carrying a mine to be selected for defusal. The following properties are required of such a function in this implementation : The following function defines an action which adheres to these requirements :
  func defuseF : currentDefused {
    if ((currentDefused>0)&&(currentDefused<=nCells)) {
      if ((status[currentDefused]!=0)&&(defuseList[currentDefused]!=0)) {
        defuseList[currentDefused]=1;
        mineTemplate[currentDefused]="X";
      } else {
        writeln("Cell already a) Uncovered, or b) Defused\n");
        dispMF();
      }
    }
  }
Hence, we now have the ability to select cells suspected of covering mines for defuse.
 
However, since we have another condition which defines whether or not a cell can be 'tried', we must modify the main function play to reflect the new change. We can introduce a new test which checks that the cell to be 'tried' has not been selected for defuse. If the cell has been selected for defuse, the cell is left alone, and the user must take another turn.
 
The modified play function appears below :
  func play : currentPos {    
    if ((pos>0)&&(pos<=nCells)) {
      if (defuseList[pos]!=1) {
        if (status[pos]==1) {        
          status[pos] = 0;        
          if (mines[pos]==1) {
            writeln("BANG ! Mine Here - Game Over");
            lost is 1;
            mineTemplate[pos]="*";          
            revealMF();        
          } else {
            if (values[pos]!="0") {
              mineTemplate[pos]=values[pos];
            } else {
              mineTemplate[pos]=labelTemplate[6]; 

              if ((((pos-1)%4)!=0)&&(pos>xDim)&&(mines[pos-xDim-1]!=1)) {
                todo("pos is "//str(pos-xDim-1)//";");
              }
              if ((((pos-1)%4)!=0)&&((pos-1)>0)&&(mines[pos-1]!=1)) {
                todo("pos is "//str(pos-1)//";");
              }
              if ((((pos-1)%4)!=0)&&(pos<=((yDim-1)*xDim))&&(mines[pos+xDim-1]!=1)) {
                todo("pos is "//str(pos+xDim-1)//";");
              }
              if ((pos<=((yDim-1)*xDim))&&(mines[pos+xDim]!=1)) {
                todo("pos is "//str(pos+xDim)//";");
              }
              if xDim)&&(mines[pos-xDim]!=1)) {
                todo("pos is "//str(pos-xDim)//";");
              }
            }
          }     
        } else {
          writeln(pos, " is already uncovered - choose another cell (1-16)");
          dispMF();
        }    
      } else {
        writeln(pos, " is a suspected mine");
        dispMF();
      }
    }
  }

 
 
Move to the eleventh TK-MineSweeper page...
 
 
 

Updated Wednesday, January 6, 1999