Binary Grid!

Hey guys, this is my first project here at Cemetech. It's called Binary Grid, based off of the app of the same name for Android. Basically the idea of the game is to switch each section of the grid from 1 to 0 so the binary string is the same as the decimal number on the outside.

I've been working on this project on and off for a bit and it is already mostly done, I mainly just need to optimize as it is a little slower than I would like. One unique thing about this game is it will work on any TI-83+ or 84+ calculator, including color screens, since it uses the home screen.

Unfortunately I do not have any screenshots or gifs of gameplay yet, but I should be able to post them soon.

Anyways, feel free to post questions or suggestions below.
This sounds really interesting for a first project, can't wait to see how it will turn out!

You say you are using the homescreen which I think is really cool. I personally really like homescreen games (not sure why, probably just because of how fantastic the large font is on the color calcs).

It'll be interesting to see how you do/are doing a selector for indicating which square is selected. I know how I'd do it I'd use a "v" at the top of the screen and a ">" on the side and where they intersect is the selected square, or flash the number every few frames but there are so many cool options available!
Since it only has a 3x3 game mode (for now at least), it uses the numpad to switch the corresponding cell between 1 and 0. In the future when larger boards are added I will just use the area around the numpad in a similar fashion.

Also yeah, some of my favorite calculator games use the home screen, it's also obviously a great way to make a program cross-calc.
So, it's been three months, and I finally remembered about this project! I did a bunch of optimization yesterday, and I got the speed up so it is actually fairly responsive. This is probably the most optimized program I have ever made, but I am definitely willing to hear any suggestions anyone has for more optimization.
Here's the code:

Code:
ClrHome
Disp "CREATING RANDOM","PUZZLE…
//random list
seq(randInt(0,7),X,1,3→L₁
//dec to bin list
If L₁(1
Then
int(2fPart(L₁(1)2^seq(X,X,⁻int(ln(L₁(1))/ln(2))-1,⁻1→L₄
Else
//if 1 is zero, store 0 because it doesn't work in the routine
{0→L₄
End
//add zeroes for padding if bin is > 3 digits
If 4>L₁(1
augment({0},L₄→L₄
If 2>L₁(1
augment({0},L₄→L₄
If L₁(2
Then
int(2fPart(L₁(2)2^seq(X,X,⁻int(ln(L₁(2))/ln(2))-1,⁻1→L₅
Else
{0→L₅
End
If 4>L₁(2
augment({0},L₅→L₅
If 2>L₁(2
augment({0},L₅→L₅
If L₁(3
Then
int(2fPart(L₁(3)2^seq(X,X,⁻int(ln(L₁(3))/ln(2))-1,⁻1→L₆
Else
{0→L₆
End
If 4>L₁(3
augment({0},L₆→L₆
If 2>L₁(3
augment({0},L₆→L₆
For(X,1,3
//get vertical dec values, store to L2
{L₄(X),L₅(X),L₆(X
sum(Ans2^(dim(Ans)-cumSum(1 or L₁→L₂(X
End
ClrHome
For(X,1,3
//output zeroes and dec values
Output(2X-1,1,"0-0-0-
Output(2X,1,"I I I
Output(2X-1,7,L₁(X
Output(7,2X-1,L₂(X
End
DelVar WDelVar K{0,0,0→L₁
Ans→L₂
Ans→L₃
Repeat W
Repeat K
getKey→K
End
If K=45
2→W
//make an list ans to access keypress data
{iPart(.1K),10fPart(.1K)-1
//modify screen and lists
If 7=Ans(1
Then
Output(1,2Ans(2)-1,not(L₁(Ans(2
not(L₁(Ans(2→L₁(Ans(2
End
If 8=Ans(1
Then
Output(3,2Ans(2)-1,not(L₂(Ans(2
not(L₂(Ans(2→L₂(Ans(2
End
If 9=Ans(1
Then
Output(5,2Ans(2)-1,not(L₃(Ans(2
not(L₃(Ans(2→L₃(Ans(2
End
//if template lists equal game board: win
If sum((L₁=L₄)(L₂=L₅)(L₃=L₆))=3
1→W
End
ClrHome
"LOSE!
If W=1
"WIN!
Disp "YOU "+Ans

(Edited to include _iPhoenix_’s changes)
Edit: removed variable L, not sure why I even used it in the first place. Comments have been added.
Also, anyone who has a color calculator or regular 83 can try this out to make sure it will work (I'm pretty sure it will).
I'll probably upload it to the archives soon if no suggestions are made.

Code:
ClrHome
Disp "CREATING RANDOM","PUZZLE…
seq(randInt(0,7),X,1,3→L₁
If not(L₁(1
Then
{0→L₄
Else
int(2fPart(L₁(1)2^seq(X,X,⁻int(ln(L₁(1))/ln(2))-1,⁻1→L₄
End
If 4>L₁(1
augment({0},L₄→L₄
If 2>L₁(1
augment({0},L₄→L₄
If not(L₁(2
Then
{0→L₅
Else
int(2fPart(L₁(2)2^seq(X,X,⁻int(ln(L₁(2))/ln(2))-1,⁻1→L₅
End
If 4>L₁(2
augment({0},L₅→L₅
If 2>L₁(2
augment({0},L₅→L₅
If not(L₁(3
Then
{0→L₆
Else
int(2fPart(L₁(3)2^seq(X,X,⁻int(ln(L₁(3))/ln(2))-1,⁻1→L₆
End
If 4>L₁(3
augment({0},L₆→L₆
If 2>L₁(3
augment({0},L₆→L₆
For(X,1,3
{L₄(X),L₅(X),L₆(X
sum(Ans2^(dim(Ans)-cumSum(1 or L₁→L₂(X
End
ClrHome
For(X,1,3
Output(2X-1,1,"0-0-0-
Output(2X,1,"I I I
Output(2X-1,7,L₁(X
Output(7,2X-1,L₂(X
End
DelVar WDelVar LDelVar K{0,0,0→L₁
Ans→L₂
Ans→L₃
Repeat W or L
Repeat K
getKey→K
End
If K=45
1→L
{iPart(.1K),10fPart(.1K)-1
If 7=Ans(1
Then
Output(1,2Ans(2)-1,not(L₁(Ans(2
not(L₁(Ans(2→L₁(Ans(2
End
If 8=Ans(1
Then
Output(3,2Ans(2)-1,not(L₂(Ans(2
not(L₂(Ans(2→L₂(Ans(2
End
If 9=Ans(1
Then
Output(5,2Ans(2)-1,not(L₃(Ans(2
not(L₃(Ans(2→L₃(Ans(2
End
If 3=sum((L₁=L₄)(L₂=L₅)(L₃=L₆
1→W
End
ClrHome
"LOSE!
If W
"WIN!
Disp "YOU "+Ans


Untested, but I did some minor optimizations that should be safe. If nobody else takes up the "job", I'll take the time to go further.

Looks pretty awesome, I'll actually dust off my CE and try it out.

Also, you should import your code into SC3. It formats things and is generally pretty awesome.
Thanks, I have used SC3 before but for this project I went with TokenIDE. I like it because I love using keyboard shortcuts for building and it is able to save a .txt file (useful for comments). SC3 is pretty great, though.
Alright, I've uploaded to the archives. I did manage to squeeze a few more bytes out of the game; the only noticeable difference is the lack of "Creating random puzzle" at the beginning as it wasn't really necessary.

You can download the game here.

As a reminder, this game is compatible with any TI calculator with an 83 or 84 in its name Smile.
Very nice, it was a lot of fun to play.

I thought I could optimize it, so I wiped the dust off my CE (haven't written any proper TI-BASIC in just over a year), reverse-engineered your program (I figured I might as well rewrite it from scratch- I wrote this without seeing your source, just the screenshot and the readme) and the result was this, 273 bytes.


Code:
// generate list of 9 (= 3x3) random bits
randInt(0,1,9->L1
// L3 = nine zeros. This is where the player board is stored.
0Ans->L3
// L2 = nine zeros, but we will only be using 6 of them, one for each hint.
Ans->L2
// the following code generates the hints.
// First time around (I=0), it generates the horizontal hints, then (I=1) it generates the vertical hints
"3J-K
For(I,0,1
   Ans->|u
   For(J,1,3
      sum(seq(L1(|u)*2^K,K,0,2->L2(J+3I
   End
   "6-3K+J
End
ClrHome
// draw a blank board, nothing crazy here
For(I,1,3
   2I-1
   Output(Ans,1,"0-0-0-
   Output(Ans,7,L2(I
   Output(2I,1,"I I I
   Output(7,Ans,L2(I+3
End
// because everything is stored in one list, we can just do one check
Repeat K=45 or 9=sum(L1=L3
   // there's a marginally faster key input routine, but it's also bigger:
  // Repeat Ans
  //   getKey
  // End
  // Ans->K
   Repeat K
      getKey->K
   End
  // keys we interested in:
  // 72 73 74
  // 82 83 84
  // 92 93 94
  //
  // column in our grid = (keycode - 1) % 10
   remainder(Ans-1,10->C
  // row in our grid = floor(keycode/10) - 7
   iPart(K/10)-7->R
  // index in our list = column + 3*row
   C+3Ans
  // check that input is within bounds
   If R>=0 and R<3 and C and C!=4
   Then
     // flip
      not(L3(Ans->L3(Ans
    // draw
      Output(1+2R,2C-1,Ans
   End
End
ClrHome
"WIN
If K=45
"LOSE
// no need for disp here, it'll show the result by itself
"YOU "+Ans


You were very, very close! I only really made two major changes, and the rest was just going around optimizing away some bytes here and there.

The first thing I did was that I only use one list. By using one list, I can write code once and use it multiple times, instead of having to rewrite my code for each list. This keeps my code DRY and was the main source of size reduction.

The second thing I did was reverse how you are creating the board. Since I'm using only one list, I can use the optional third parameter of the randInt(<lower>, <upper>, [<amount>] command and generate my grid all at once. Generating the "hints" first, then taking those hints and creating the board is the obvious strategy, but it's much easier to generate the board and then create the hints.

If you have any questions on what any line does or why I did something the way I did, let me know!
Wow, this is really good! I knew there had to be a way to make the beginning part less redundant, but I never would have come up with this.

Also, for some reason I forgot/didn't know about the optional third argument for randInt( Rolling Eyes .

Anyways, thanks for optimizing; I learned a lot from this!
Now that you're done, are you planning on adding new modes (4x4, 3x4, custom selection of size, etc.)?
bdoggamer wrote:
Now that you're done, are you planning on adding new modes (4x4, 3x4, custom selection of size, etc.)?

I actually wasn't planning on it originally, but with the updated code more modes are certainly more possible, so if you are interested I definitely could try.
Jeffitus wrote:
bdoggamer wrote:
Now that you're done, are you planning on adding new modes (4x4, 3x4, custom selection of size, etc.)?

I actually wasn't planning on it originally, but with the updated code more modes are certainly more possible, so if you are interested I definitely could try.

I definitely would, because I downloaded the original, and enjoy it very much. After a while though, it becomes very easy. I don't know how you would do the menus though, so it could be a challenge.

PS One time I ran the program, it generated all of the 'goals' as 0. I just clicked a square twice and won. Don't know if you want to have an if statement checking for that so there is always a game.
So, I've been experimenting with larger grid sizes, and the question I have for people is which one of these would you prefer:





The images are mock-ups of what the maximum sized grid would be, and I'm not entirely sure which one I should use. In my opinion the second looks less cramped, but I just want to hear what other people think.

Also, thanks bdoggamer for bringing to my attention the all zeroes bug, that can easily be fixed.
Jeffitus wrote:
So, I've been experimenting with larger grid sizes, and the question I have for people is which one of these would you prefer:


I definitely agree, the second one looks way less cramped and thus better, in my opinion.

PS-In your screenshots, you have a grid with 6 width and 5 length. This is fine, but they both display 31. Wouldn't the width side maximum be 63? You might have just used it as a place holder, just checking.
bdoggamer wrote:
PS-In your screenshots, you have a grid with 6 width and 5 length. This is fine, but they both display 31. Wouldn't the width side maximum be 63? You might have just used it as a place holder, just checking.


Yes, it was just a placeholder, but as it turns out I will have to make the limit 5x5 anyways, due to the calculator only having 5 columns of keys. I must have overlooked this Rolling Eyes .

An updated version with 5x5 grid support should be released later today next week Smile .

(Getting the controls to work could take some time)
Well, it's been more than a week, but I've finally finished version 1.2 of Binary Grid.

New features include _iPhoenix_'s optimizations, 4x4 and 5x5 puzzles, and a check to make sure the puzzle is not all zeroes at the beginning. I've also updated the readme with information on controls for larger boards and some notes.

Edit: Download the new version from the archives here.
thanks for the post!
  
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 UTC - 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