MineSweeper 5250 v3.1415

MineSweeper 5250 is a text implementation of a game that came free
with the operating system on one of my home machines.
-----------------------------------------------------------------------

Rules:

F1 marks a square
F2 flips a square
F3 flips all squares adjacent to a square that has already been:
   a. marked
   b. flipped
F4 starts a new game
F5 ends the program

and, the features what's their name wouldn't give us -

F11 - replay game
F12 - flip random square


Remember, this game is for demonstration purposes only. No one would
ever, ever, play this at work. Now, excuse me. I have to get an ice
pack for my wrist.




This program is an example of a "bottom-up" implementation, by which it
is meant that there is no top-down code in the mainline (and very
little anywhere else).

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *                                                               * *
* * *                        Mainline                           * * *
* *                                                               * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 /free
  *InLR = *On;

  procProxy@ = init();
  DoU ( procProxy@ = *NULL );
     procProxy@ = procProxy();
  EndDo;

  Return;
 /end-free
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

@procProxy@ is an array of procedure pointers
procProxy@  is a procedure pointer
procProxy   is a pointer-based procedure

To start, the procedure init() is called. init() returns the pointer
to the first procedure to be executed.

Every "state" procedure is responsible for returning the pointer to
the next procedure to be executed. This is determined by examining
state variables. When the program is over, a null pointer is returned.

The following is an example of code examining state variables, and
determining the next state procedure to execute:

       If ( countFound = MINECOUNT And countMissd = 0 );
          Return @procProxy@(WON);
       Else;
          Return @procProxy@(PLAYGAME);
       EndIf;

Procedures can be divided into "State" and "Service". Service
procedures are not allowed to modify state variables. This allows
us the option of exporting them to a service program during the
design phase.

The program also uses recursion, and the procedures CEERAN0 (a bindable
ILE procedure) and memset (from the C run-time library).

cp1015.txt - MineSweeper 5250 v3.1415

The file cp1015.txt actually contains five members:



Valid HTML 3.2! Creative Commons License

BrilligWare/ chris@pando.org / revised August 2005