Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is a minesweeper clone that I made, and I've drastically improved the speed since my last post!
Here's the code if you're curious:

Code:
8->Z   //Title
"Minesweeper"->Str1
prgmZTITLE
Input "Difficulty, 5 is best      ",F
Output(4,5,"Generating Terrain..."
{10,26->dim([A]
{10,26->dim([B]
For(A,1,10
   For(B,1,26
      If A=1 or A=10 or B=1 or B=26
      Then
         11->[A](A,B
      Else
         0->[A](A,B
      End
      If not(randInt(0,F)) and not([A](A,B   //Place Mines
      Then
         1->[B](A,B
      Else
         0->[B](A,B
      End
      If [A](A,B)=11      //Drawing
      Then
         Output(A,B,"+"
      Else
         Output(A,B,"-"
      End
   End
End
2->A
2->B
Repeat K=105   //Place Starting Area
   getKey->K
   A+(K=34)-(K=25->A
   B+(K=26)-(K=24->B
   Output(A,B," "
   If [A](A,B
   Then
      Output(A,B,"+"
   Else
      Output(A,B,"-"
   End
End
1->[A](A,B
Output(A,B,0
For(C,A-1,A+1   //Clear Starting Area
   For(D,B-1,B+1
      0->[B](C,D)
   End
End
Repeat K=23      //Main Loop
   105->K      //Auto Search
   For(E,2,9
      For(F,2,25
         If [A](E,F)=1
         Then
            E->G
            F->H
            For(A,E+1,E-1,~1
               For(B,F+1,F-1,~1
                  If not([A](A,B
                  Then
                     Goto A
                     Lbl B
                     If [A](A,B)=1 and (A<G or (A=G and B<H
                     Then
                        A->G
                        B-1->H
                     End
                  End
               End
            End
            G->E
            H->F
         End
      End
   End
   DelVar EDelVar K
   Repeat K=75 or K=23      //Key Loop
      getKey->K
      If K
      Then
         A+(K=34)-(K=25->A   //Movement
         B+(K=26)-(K=24->B
         If K=95 and not([A](A,B      //Flagging
         Then
            10->[A](A,B
         Else
            If K=95 and [A](A,B)=10
               0->[A](A,B
         End
         If K=85      //Win Check
         Then
            1->E
            For(C,2,9
               For(D,2,25
                  If not([A](C,D
                     0->E
                  If [A](C,D)=10 and not([B](C,D
                     0->E
               End
            End
            If E
            Then
               DelVar E
               "A winner is you!!"->Str1
               6->Z
               prgmZTITLE
               23->K
            End
         End
         Lbl A
         If K=105 and not([A](A,B   //Searching
         Then
            If not([B](A,B
            Then
               1->[A](A,B
               For(C,A-1,A+1
                  For(D,B-1,B+1
                     [B](C,D)+[A](A,B->[A](A,B
                  End
               End
            Else
               23->K
               "BOOM!"->Str1
               12->Z
               prgmZTITLE
            End
         End
      End
      Output(A,B," "      //Drawing
      If [A](A,B
      Then
         If [A](A,B)<10
         Then
            Output(A,B,[A](A,B)-1
         Else
            If [A](A,B)=10
            Then
               Output(A,B,"F"
            Else
               Output(A,B,"+"
            End
         End
      Else
         Output(A,B,"-"
      End
      If E
         Goto B
   End
End
ClrHome

And here's a drive link to download the required files. The title program must be named "ZTITLE".
https://drive.google.com/open?id=1UQ4ko-BUW4G2LFbbtVLEYzOrZM7T-g4j

The controls are:
enter to search a space
+ to flag a space
- to check for a win
x to run the auto search function that searches zero adjacent spaces (runs once at the beginning by default)

The difficulty setting represents the chance that a mine will be placed in any given space (1/difficulty+1). For example, 5 means that 1 in 6 spaces will be a mine.

Let me know what you think, and happy sweeping!
Nice! If you want to provide a download for the program I'm sure people would appreciate that too (including ZTITLE as well). Even if you don't upload to archives you could share via Google Drive or Mediafire.
There are many ways to speed it up-- in an unoptimized TI-BASIC program interpreter overhead can be >90% of the execution time. For a start, you should unroll this:


Code:
         For(C,A-1,A+1
            For(D,B-1,B+1
               If [B](C,D
                  1+[A](A,B->[A](A,B
            End
         End

into this:

Code:
[A](A,B)+sum(seq([B](C,B-1)+[B](C,B)+[B](C,B+1),C,A-1,A+1->[A](A,B


Many of the inner loops can be replaced with similar one-liners, often more clever than this.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement