[Coco] Minesweeper
Robert Gault
robert.gault at worldnet.att.net
Mon Feb 6 07:07:01 EST 2006
Hi Diego,
Minesweeper is a nice little program. Good job!
Given that Minesweeper was written to use the 32 column text screen,
there not much if anything you could do to improve the appearance of the
game. The game controls work well and are fast, so again there isn't
much possible in the way of improvement. That just leaves some comments
about the setup coding. Here are some I put together that you might find
useful.
----------------------------------------
Minesweeper Notes
1) You can tell whether a Coco is a "3" by looking at the word content
of $FFFE. A Coco3 has a reset vector of $8C1B. That means lines 10 & 20
can be automatic.
10 IF PEEK(&HFFFE)=140 THEN POKE65497,0:WIDTH32 ELSE POKE65495,0
2) You can get better random numbers by resetting the random number
generator with a random seed. If not, you could have the same mine field
with each time you play the game immediately after turning on your Coco.
A=RND(-TIMER) will do the job of "randomizing" the random number seed.
3) It is not necessary to initialize variables to zero in Basic, it's
automatic. That means line 60 is not needed. However, since the program
restarts not with RUN but GOTO50, it is necessary to find a fast way to
zero out the array on a rerun. Change line 40 to 40 CLEAR:DIM M(27,14)
and make the program restart with GOTO40.
4) In theory, the assignment of mines could be improved. The current
method is analogous to throwing darts at a map divided into 338 squares.
Darts are thrown until there are 45 darts on the map, each in a
different square. This could take a very long time if the darts keep
hitting the same squares, which is possible.
Another analogy is a bag of 338 marbles each labeled with a different
number. Pull out 45 marbles and the mines go on the squares
corresponding to the marbles. There can't be any multiple hits of the
same squares.
The question is can the second routine be programmed in as simple a
fashion as the first. I have not been able to write a Basic program
using method 2 that is even close to method 1 in speed, even though
method 2 is the better method. It is a good example of complexity
overwhelming speed.
Care to guess how the speed of method 1 will be affected by increasing
the percentage of the mined area?
Diego Barizo wrote:
> I'm going to start a new version of the "Minesweeper" game that I wrote
> for the Xmas Coconutz magazine.
> But I figured that some of you might have some suggestions, criticisms,
> whatever.
> Even a "How did you write that %&@*!" as long as it comes with something
> like "you should have done it like this!" will be welcome.
> Thanks,
> Diego
>
> P.S. while writing this, I wrote @ instead of ".
> I wonder why my fingers expect the " to be on the 2 key ;-)
>
More information about the Coco
mailing list