Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Deep Toaster on November 20, 2011, 08:42:42 pm

Title: Mine
Post by: Deep Toaster on November 20, 2011, 08:42:42 pm
MIENCR4F7 IN TI-BASIC W0000T!!!11

J/k, I wish :P It's actually Minesweeper, but with flood-fill and everything! :D

http://img.removedfromgame.com/imgs/mine.gif

That's full speed on a TI-84 Plus, so you can tell that the flood-filling is a bit slow. I'm still trying to improve it, but the code's about as optimized as I can get it right now O.O

Multiple levels coming soon. It's actually fully implemented; all I need to do is add a menu.

LATEST UPDATE: http://omniurl.tk/11535/211326/

(http://img.removedfromgame.com/imgs/0-mine.gif)
Title: Re: Mine
Post by: mrmprog on November 20, 2011, 08:44:32 pm
OMGZ! Minecraft! With better graphics!
Seriously, nice job. +1
Title: Re: Mine
Post by: zeldaking on November 20, 2011, 08:46:15 pm
Looks pretty good for a ti-basic. A lot better than my version, which is very dumb. I like the white on black.
Title: Re: Mine
Post by: epic7 on November 20, 2011, 08:48:12 pm
I never figured out how the heck to play minesweeper.
Title: Re: Mine
Post by: Deep Toaster on November 20, 2011, 08:49:28 pm
What sort of fields should I use for medium/hard mode? The mode in the screenshot is Windows-classic Beginner (9x9 board with 10 mines), but their Intermediate and Expert modes (16x16 and 30x16) don't exactly fit on a calculator screen :P
Title: Re: Mine
Post by: mrmprog on November 20, 2011, 08:50:25 pm
What size are the squares now?
Title: Re: Mine
Post by: Deep Toaster on November 20, 2011, 08:51:10 pm
Each square is 5x5 with a border of one between any two rows/columns.
Title: Re: Mine
Post by: epic7 on November 20, 2011, 08:55:31 pm
Make more mines for hard
Title: Re: Mine
Post by: mrmprog on November 20, 2011, 09:05:09 pm
So with that, 16*10 is the max size?
Title: Re: Mine
Post by: BrandonW on November 20, 2011, 09:22:06 pm
Your description implies you aren't randomly generating new boards. Why not?
Title: Re: Mine
Post by: BalancedFury on November 20, 2011, 09:23:03 pm
MIENCR4F7 IN TI-BASIC W0000T!!!11

J/k, I wish :P It's actually Minesweeper, but with flood-fill and everything! :D

(http://img.removedfromgame.com/imgs/mine.gif)

That's full speed on a TI-84 Plus, so you can tell that the flood-filling is a bit slow. I'm still trying to improve it, but the code's about as optimized as I can get it right now O.O

Multiple levels coming soon. It's actually fully implemented; all I need to do is add a menu.
Just some ideas but you should make the mines/ bombs into creepers XD
Title: Re: Mine
Post by: Deep Toaster on November 20, 2011, 09:52:12 pm
Your description implies you aren't randomly generating new boards. Why not?
I am; I'm just trying to decide what board sizes to use for the other difficulty levels.
Title: Re: Mine
Post by: ztrumpet on November 20, 2011, 10:07:22 pm
Very nice, Deep.  Great job on this, as always.
Title: Re: Mine
Post by: Builderboy on November 20, 2011, 10:28:06 pm
Cool!  What kind of flood fill algorithm are you using?  Often times the difference in speed is not due to optimization, but algorithm :D
Title: Re: Mine
Post by: Deep Toaster on November 20, 2011, 10:39:30 pm
Yeah, I know why it's slow, and it's because my algorithm is pretty bad :/ Here's my flood-fill code:
Quote from: TI-BASIC
{~1.01,~.01,.99,~1,1,~.99,.01,1.01->L3
DelVar I{A+sub(B->L2
Repeat I=dim(L2
I+1->I
L2(Ans
F+pxl-Test(600fPart(Ans)+2,6iPart(Ans)+2->F
sum(seq(max(L1=L2(I)+L3(J)),J,1,8
If Ans
Then
" "+sub("12345678",Ans,1)+"
Else
For(J,1,8)
L2(I)+L3(J
If Ans>=0 and iPart(Ans)<C and |E2fPart(Ans)<D and prod(L2-Ans
Ans->L2(1+dim(L2
End
"     
End
Text(600fPart(L2(I))+1,6iPart(L2(I))+2,Ans
End
The stuff between lines 11 and 15 are what's really slowing the thing down. It goes through the eight surrounding pixels and individually tests them to see if they're valid or not, and if so they get appended to the queue (L2). Because it has to do this for every element on the queue that doesn't have any mines surrounding it, blank squares take a while to show up.

I tried to implement the third algorithm on the Wikipedia article (http://en.wikipedia.org/wiki/Flood_fill), but since there are eight directions in Minesweeper and three classes of elements (blank, numbered, mine), it turned out to be even slower than the one I have.
Title: Re: Mine
Post by: Stefan Bauwens on November 21, 2011, 11:43:26 am
Looks nice, Deep. :)
Title: Re: Mine
Post by: aeTIos on November 21, 2011, 01:16:52 pm
I never figured out how the heck to play minesweeper.
Then learn cause fun to play
Title: Re: Mine
Post by: saintrunner on November 21, 2011, 04:48:46 pm
really good! one of the best versions I've seen yet!
Title: Re: Mine
Post by: jacobly on November 22, 2011, 03:23:22 am
Yeah, I know why it's slow, and it's because my algorithm is pretty bad :/ Here's my flood-fill code:
Quote from: TI-BASIC
{~1.01,~.01,.99,~1,1,~.99,.01,1.01->L3
DelVar I{A+sub(B->L2
Repeat I=dim(L2
I+1->I
L2(Ans
F+pxl-Test(600fPart(Ans)+2,6iPart(Ans)+2->F
sum(seq(max(L1=L2(I)+L3(J)),J,1,8
If Ans
Then
" "+sub("12345678",Ans,1)+"
Else
For(J,1,8)
L2(I)+L3(J
If Ans>=0 and iPart(Ans)<C and |E2fPart(Ans)<D and prod(L2-Ans
Ans->L2(1+dim(L2
End
"    
End
Text(600fPart(L2(I))+1,6iPart(L2(I))+2,Ans
End
The stuff between lines 11 and 15 are what's really slowing the thing down. It goes through the eight surrounding pixels and individually tests them to see if they're valid or not, and if so they get appended to the queue (L2). Because it has to do this for every element on the queue that doesn't have any mines surrounding it, blank squares take a while to show up.

I tried to implement the third algorithm on the Wikipedia article (http://en.wikipedia.org/wiki/Flood_fill), but since there are eight directions in Minesweeper and three classes of elements (blank, numbered, mine), it turned out to be even slower than the one I have.

Replacing the above code with
Code: [Select]
:A+sub(B
:sum(seq(max(L₁=Ans+L₃(I)),I,1,8
:If Ans
:Then
:Text(6B+1,6A+2," "+sub("12345678",Ans,1)+"
:Else
:Text(6B+1,6A+2,"    
:DelVar I{A+sub(B➔L₂
:Repeat I=dim(L₂
:I+1➔I
:For(J,1,8
:L₂(I)+L₃(J
:If Ans≥0 and iPart(Ans)<C and ᴇ2fPart(Ans)<D
:Then
:If pxl-Test(600fPart(Ans)+2,6iPart(Ans)+2
:Then
:sum(seq(max(L₁=L₂(I)+L₃(J)+L₃(K)),K,1,8
:If Ans
:Then
:" "+sub("12345678",Ans,1)+"
:Else
:L₂(I)+L₃(J➔L₂(1+dim(L₂
:"    
:End
:Text(600fPart(L₂(I)+L₃(J))+1,6iPart(L₂(I)+L₃(J))+2,Ans
:End
:End
:End
:End
:End
appears faster, although it could probably be optimized some more.

Edit to show how good I am at minesweeper ;)
J/k, actually to see the speed difference (I hope).
Title: Re: Mine
Post by: Deep Toaster on November 22, 2011, 09:42:20 am
I was *just* about to post that I made the engine about 50% faster by using a pxl-Text XD But yep, there really is a noticeable difference. Thanks anyway for taking the time to help :)

I've also added the menu, timing, and all that other stuff I was going to add. I'll post an update later today.
Title: Re: Mine
Post by: Deep Toaster on November 24, 2011, 03:05:04 pm
Major update! This version has everything I mentioned above, plus slight GUI changes (flags are now white on black to distinguish them from numbered squares), plus the my most beautiful pure-BASIC title screen yet:

(http://img.removedfromgame.com/imgs/0-mine.gif)
Title: Re: Mine
Post by: Deep Toaster on November 28, 2011, 12:22:36 am
Well, I've decided. This will be my zContest entry for the TI-BASIC section unless (until) I finish Madness.