minesweeper

Show us what you're working on, (preferably with screenshots).
Post Reply
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

minesweeper

Post by Jbizzel »

a little minesweeper game I've been playing about with between other projects....


Image
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

Image

wip
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

different colours to show where the correct flags, and incorrect flags were placed.

(yes, there is a bug top right)

Image
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

getting there.

still plenty of bugs and additional functionality to make it a proper game, but its playable after a fashion.

Image



Image
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: minesweeper

Post by RMartins »

Is this being done in BASIC ?
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

I'm doing it in ZX Basic by [mention]boriel[/mention]

With a few simple ASM routines

I think it would be too slow in basic

I actually thought it would be quick and simple, but its more complicated that I first thought. The main thing missing at the moment is that is you hit a blank square then it opens up all blanks on the board, but it needs to only open the ones that are connected.

Apart from that and a few bugs the game works now
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: minesweeper

Post by RMartins »

Jbizzel wrote: Mon Feb 14, 2022 12:24 am ...
I actually thought it would be quick and simple, but its more complicated that I first thought. The main thing missing at the moment is that is you hit a blank square then it opens up all blanks on the board, but it needs to only open the ones that are connected.
...
Actually, that is not that hard, you just need to visit every single neighbor of that cell (up,down, left and right), maybe diagonals too (depending how you want it to open), using a depth first traversal (better used of memory), being the only concern to mark the cells where you have already been in previously (while traversing).

That is the typical implementation.

I explained it graphically (animation/video) in my Arcade game port to ZX Spectrum FOSDEM presentation.
Dr beep
Manic Miner
Posts: 381
Joined: Mon Oct 01, 2018 8:53 pm

Re: minesweeper

Post by Dr beep »

RMartins wrote: Sun Feb 13, 2022 11:51 pm Is this being done in BASIC ?

I made a BASIC - oneliner in the '80-ies

Game 11, BASIC-line 22

Only missing the automatic find all empty places.

https://spectrumcomputing.co.uk/entry/1 ... /ONELINERS
Dr beep
Manic Miner
Posts: 381
Joined: Mon Oct 01, 2018 8:53 pm

Re: minesweeper

Post by Dr beep »

RMartins wrote: Tue Feb 15, 2022 7:24 pm
Jbizzel wrote: Mon Feb 14, 2022 12:24 am ...
I actually thought it would be quick and simple, but its more complicated that I first thought. The main thing missing at the moment is that is you hit a blank square then it opens up all blanks on the board, but it needs to only open the ones that are connected.
...
Actually, that is not that hard, you just need to visit every single neighbor of that cell (up,down, left and right), maybe diagonals too (depending how you want it to open), using a depth first traversal (better used of memory), being the only concern to mark the cells where you have already been in previously (while traversing).

That is the typical implementation.

I explained it graphically (animation/video) in my Arcade game port to ZX Spectrum FOSDEM presentation.
In fact, you can do it without a depthsearch.
I coded the game in 1K on a ZX81 and I had no room to use a depthsearch.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

Thanks for the replies, I'll check those links out as I'm not familiar with the technique.

I've got the algorithm working and just need to debug everything.

I do this:

If you click a 0 (not a bomb, and not touching a bomb)
Add all 8 neighbors to a check list
Flag them so they can't be added twice
Then the print routine visits the check pile x and y of each item and prints it on screen. If the checked item is a 0 then it checks all 8 neighbors and adds them to the check pile.

It keeps going until the check pile is empty. No cell can be added to the pile twice.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

Dr beep wrote: Wed Feb 16, 2022 4:36 pm
RMartins wrote: Sun Feb 13, 2022 11:51 pm Is this being done in BASIC ?

I made a BASIC - oneliner in the '80-ies

Game 11, BASIC-line 22

Only missing the automatic find all empty places.

https://spectrumcomputing.co.uk/entry/1 ... /ONELINERS
The first version I made, when you found a blank it revealed every blank, and their neighbours. That's actually very playable.

It also starts the player on a square that has no bombs.

I know it's possible to have a game board that is always solvable without guessing, but I have no idea how that would work.
Dr beep
Manic Miner
Posts: 381
Joined: Mon Oct 01, 2018 8:53 pm

Re: minesweeper

Post by Dr beep »

Jbizzel wrote: Sat Feb 19, 2022 12:52 am Thanks for the replies, I'll check those links out as I'm not familiar with the technique.

I've got the algorithm working and just need to debug everything.

I do this:

If you click a 0 (not a bomb, and not touching a bomb)
Add all 8 neighbors to a check list
Flag them so they can't be added twice
Then the print routine visits the check pile x and y of each item and prints it on screen. If the checked item is a 0 then it checks all 8 neighbors and adds them to the check pile.

It keeps going until the check pile is empty. No cell can be added to the pile twice.
that is how my 1K version on the ZX81 works to prevent a large stack.
it also reveals all fields adjecent to a bomb when you start on a space, like it should.
Except that the field is stored invisible on the screen all the time.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

It's good to know.

I've tried not to look at how this should be done. Part of the fun is trying to solve how to do it from scratch, only by playing the game.

Although I did start looking at alternative rules and versions of the game. So there is some scope for doing something that has never been done on the spectrum.

My code is so close now to a full working game. Just a few *bug* - or rather coding mistakes I have made that I can't see!

I don't think this game needs music, I'll probably just leave it with some minimal beeper fx
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

https://youtube.com/shorts/nnxgMsPAbrE?feature=share

Here's the algorithm in action. With bugs. Fixed a few of them now, but there is still some strange stuff happening
Dr beep
Manic Miner
Posts: 381
Joined: Mon Oct 01, 2018 8:53 pm

Re: minesweeper

Post by Dr beep »

Jbizzel wrote: Sat Feb 19, 2022 4:12 pm https://youtube.com/shorts/nnxgMsPAbrE?feature=share

Here's the algorithm in action. With bugs. Fixed a few of them now, but there is still some strange stuff happening
Here is my 1K version. With hilaric gameplay by Rod Bell

https://www.youtube.com/watch?v=ou4t4FLfnls
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

Dr beep wrote: Sat Feb 19, 2022 5:47 pm
Jbizzel wrote: Sat Feb 19, 2022 4:12 pm
Here's the algorithm in action. With bugs. Fixed a few of them now, but there is still some strange stuff happening
Here is my 1K version. With hilaric gameplay by Rod Bell
1k thats amazing. Is it ASM? its super fast.

interesting to see your "clear 0s algorithm" looks very similar to mine - yours does a big diagonal trip across the field if it can. Mine does exactly the same thing! I've put a delay in so I can watch it go :)

My major milestone today is that I've removed every GO TO statement from the game.

It would be interesting to do a pure basic version.
User avatar
patters
Manic Miner
Posts: 471
Joined: Thu Apr 11, 2019 1:06 am

Re: minesweeper

Post by patters »

Jbizzel wrote: Sat Feb 19, 2022 6:34 pmMy major milestone today is that I've removed every GO TO statement from the game.
Very satisfying when you do that in ZX BASIC isn't it.

I love the loading screen!
Dr beep
Manic Miner
Posts: 381
Joined: Mon Oct 01, 2018 8:53 pm

Re: minesweeper

Post by Dr beep »

Jbizzel wrote: Sat Feb 19, 2022 6:34 pm
1k thats amazing. Is it ASM? its super fast.
Yes it is ASM for multiple reasons
1) commands take less room, no length of line or length of data shorter ( 1 byte can hold a number from 0 to 255)
2) speed indeed

source can be obtained here

https://sinclairzxworld.com/viewtopic.p ... 077#p31077
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

Here's my code for what its worth - still WIP but completely playable and no obvious show stopper bugs. Although, when I finish I we release it officially as a tap with a loading screen.

https://gitlab.com/JB1zzel1/mine-sweeper-zx-spectrum

A key feature on this version is that it will place the player on a square that is safe, and not touching a bomb. I think this gives it a modern aspect.

Once question [mention]Dr beep[/mention] and others, is how best to generate the field of bombs?

My game goes through the array, and in each location randomly determines if there is a bomb there. On hard mode - more change of bombs. Is there a better of different way to do it?
Dr beep
Manic Miner
Posts: 381
Joined: Mon Oct 01, 2018 8:53 pm

Re: minesweeper

Post by Dr beep »

Jbizzel wrote: Sun Feb 20, 2022 9:16 pm
Once question @Dr beep and others, is how best to generate the field of bombs?
I simply select a random field, test if it already has a bomb, if not set bomb, increase fields around. Repeat until all bombs are set.
User avatar
Jbizzel
Dynamite Dan
Posts: 1537
Joined: Mon May 04, 2020 4:34 pm
Location: Hull
Contact:

Re: minesweeper

Post by Jbizzel »

I actually hadn't thought of doing it that way. Mine is more random so you get a varying amount of mines on each skill level.

I might have a go at your solution and see if it feels better. I suppose it would then be easy to ask the user how many bombs they want in the game and give them an exact amount.
Post Reply