Interaction & Play


Overview Of Current State Of TK-MineSweeper

Perhaps the most complex task in creating TK-MineSweeper is actually defining the rules which make the model run like the original mineSweeper game. This section deals with this aspect of the model. It is intuitative to look at what we already have at this point before seeing how we can start to tie it all together into one coherant module.

Now, therefore, we need to see how all of these elements can be tied together in order to make the model work as a game.

Breakdown Of Play

The playing of minesweeper can be broken down to produce a set of checks which define what actions should be taken. The following list looks in detail at an interaction with mineSweeper :

  if ((currentPos > 0)&&(currentPos <= nCells)) {
    CONTINUE
  } else {
    writeln("Choice of cell out of range - try another (1-16)");
  }
  if (status[currentPos]==1) {
    CONTINUE
  } else {
    writeln("Cell is already uncovered - try another (1-16)");
  }
  if (mines[currentPos]==1) {
    writeln("BANG ! Oops - found a mine the messy way");
  } else {
    CONTINUE
  }
  if (values[currentPos]!="0") {
    mineTemplate[currentPos] is values[currentPos]
  } else {
    UNCOVER 8-CONNECTED CELLS
  }
This defines the important checks which must take place within this aspect of the model. Basically, we can simplify this in English as follows :

8-Connected Check

Whilst the majority of this section is quite simple, the most tricky part concerns the plan of action when a blank cell is encountered. This is so because this leads to further uncovering of other cells, which, in turn, could lead to further uncovering. For this action, a TKeden operation called todo comes in very useful.
 
When executing, TKeden will simply execute it's current thread of events. However, if we wish to schedule certain events, then we can use the todo list.
 
The todo list is a list within TKeden, which is executed once the current thread of events has been exhausted. Hence, we get the execution of actions in a specified sequence.
 
Take into consideration that we have chosen a cell on the mineField , and it turns out to be a blank. Now, we must check 8-connected cells to uncover further cells until we reach cells which have surrounding mines. The following diagram illustrates the 8-connected model used in the TK-MineSweeper model :

  123
  4 5
  678
So, we must check these 8-connected cells, and reveal their contents. If a cell contains some value>0, then we display the value and halt there. If the cell contains 0, then we perform the 8-connected search on that cell in addition to the current cell.
 
Taking the 8-connected diagram into consideration, we use the following references to reference the 8-connected items : These conditions are a concatenation of four simple conditions defined and explained below :

The PLAY Function

Armed with all of this information, we may tackle the definition of the play function. Before getting into the function itself, we need to answer the question - when do we want the model to perform our checks ?
 
It would seem as though the best time to perform these checks would be whenever the player changes the value of currentPos. Hence, we make the function, play, a triggered action.
 
Get ready - here comes the play function - copy & paste & Accept :

  func play : currentPos {
    if ((pos>0)&&(pos<=nCells)) {
      if (status[pos]==1) {
        status[pos] = 0;
        if (mines[pos]==1) {
          writeln("BANG ! Mine Here - Game Over");
          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]!=1)) {
              todo("pos is "//str(pos-xDim+1)//";");
            }
            if ((pos>xDim)&&(mines[pos-xDim]!=1)) {
              todo("pos is "//str(pos-xDim)//";");
            }
          }
        }
      } else {
        writeln(pos, " is already uncovered - choose another cell (1-16)");
        dispMF();
      }
    }
  }
}
Within the above extract of code for the play function, where the check occurs near the top to see whether pos is a cell containing a mine or not, when it is found that pos is a mine, there is a commented out routine, revealMF();
 
This function is designed to simply reveal all elements on the mineField when the player loses, so that the position of everything can be seen. This is a comparatively simple function, and appears below. Once this function has been defined, the commented out reference in the play function can be uncommented.
  func revealMF {
    auto x;
    for (x=1;x < nCells;x++) {
      mineTemplate[x]=values[x];
      if (mines[x]==1) mineTemplate[x]="*";
      if (values[x]==0) mineTemplate==" ";
    }
  }
Quite simply, this function runs through all cells from cell 1 to nCells, substituting the ?'s in mineTemplate for a) * - for mines, b) " " - for blanks, and c) value[x] - for values.
 
With these functions in place, it is quite possible to have a game of TK-MineSweeper. Simply make some changes to the value of currentPos to designate plays, and you may negotiate the minefield.
 
Whilst it is interesting rambling around our TK-MineField, we still have no way of winning (even though we have a way of losing). This is mostly due to a large ommision in the implementation which is about to be included - that of the mineSweeper hero's ability to select cells which he/she suspects contains mines for defusal.
 
Further inclusions to the current implementation of TK-MineSweeper will introduce the ability to select defuse cells, as well as defining a way of winning the game.

 
 
Move to the ninth TK-MineSweeper page...
 
 
 

Updated Wednesday, January 6, 1999