Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Minesweeper clone - demo added
#31
I have been trying to make minesweeper myself recently, it will be no where near as good as yours but thats just a matter of graphics, I'm doing it more for the fun of working out the code.

I have the same problem with the blank tiles:

Calling a sub for every blank tile is ok but if you had this sort of situation:
1 = 1 mine
0 = no mines
pretty self explanitatry really

1 1 1
1 0 1
1 0 1
1 0 1
1 1 1


if you click the middle 0 then it runs the sub and sees one above and one below, it reveals all tiles around the middle o and then check th top 0. surely then it will recognise the middle one again, which then will recognise the top one again... etc...

do you understand? kindda confusing
eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
Reply
#32
Quote:I have been trying to make minesweeper myself recently, it will be no where near as good as yours but thats just a matter of graphics, I'm doing it more for the fun of working out the code.

I have the same problem with the blank tiles:

Calling a sub for every blank tile is ok but if you had this sort of situation:
1 = 1 mine
0 = no mines
pretty self explanitatry really

1 1 1
1 0 1
1 0 1
1 0 1
1 1 1


if you click the middle 0 then it runs the sub and sees one above and one below, it reveals all tiles around the middle o and then check th top 0. surely then it will recognise the middle one again, which then will recognise the top one again... etc...

do you understand? kindda confusing

Thats what we were taliing about. But we were also talking about the stack space, something about how many times you can call a sub within a sub( due to memory?). Anyway if you wouldn't use subs how would you work it then?
Reply
#33
See my code. Instead of using recursive calls, you use a stack. Pseudocode is:

0.- Clear stack.
1.- You add the current position to the stack.
2.- Check around. If any of the surrounding cells doesn't have a mine, push its position to the stack.
3.- Loop to 1 until stack is clear.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#34
IMO recursive functions are very dangerous if not used properly. But theres always a walk around. But this one seems to be difficult. I have a very vague idea based on a floodfill routine.
Reply
#35
Quote:See my code. Instead of using recursive calls, you use a stack. Pseudocode is:

0.- Clear stack.
1.- You add the current position to the stack.
2.- Check around. If any of the surrounding cells doesn't have a mine, push its position to the stack.
3.- Loop to 1 until stack is clear.

Well I really want to keep clear of stacks because I really don't know what they are. Anyone got any help on that?
Reply
#36
A stack is a data structure. Imagine you have a pile of documents. You can add documents only at the top of the pile, and you can extract documents from the pile only from the top. That's how a stack works. Look at the code snippet I posted some days ago. There is a very simple implementation of a stack using an array. It usually features four operations: 1.- Clear Stack (delete all the element), 2.- Push (adds a new element, 3.- Pop (retrieves and eliminates the element on top), and 4.- IsEmpty (returns TRUE if the stack is empty).

Imagine you have a integer stack, that is, you can stuff integers inside:

Code:
_ (empty stack)

You insert a value, for example 7 (push 7):

Code:
7
_

Now you insert another value, for example 2 (push 2):

Code:
2
7
_

Now another one, for example 6 (push 6):

Code:
6
2
7
_

Now, you can extract values from the stack:

Code:
WHILE NOT IsEmpty%()
   a% = Pop%()
   PRINT a%
WEND

Which will print on screen:

Code:
6
2
7

FUNCTION and SUB calls use the stack to store the parameters and return address. I am just simulating a recursive call using a custom stack only to store the data I really need (a recursive call would store the stack frame + the parameters + space for the local variables, that can be a lot of bytes per call (per iteration!), and I only use 4 bytes: two integers, x and y for iteration).
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#37
http://qbnz.com/pages/forum/viewtopic.php?t=351
That's a set of stack structure functions I made a while ago. It also explains what a stack is. But Nath explained that well. Smile
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#38
Hmm thanks. I was thinking of toying with the idea of using a dynamic array, but this sounds better.
Reply
#39
Quote:STL = Standard Template Library. A c++ programmer should always know hoe to use it =).
My hoe knows how to use it. Big Grin

j/k :lol:
I'd knock on wood, but my desk is particle board.
Reply
#40
You devil. Picking on me :evil:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)