Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: JWinslow23 on November 11, 2013, 12:35:52 pm

Title: Shutdown (a clone of Lights Out Deluxe)
Post by: JWinslow23 on November 11, 2013, 12:35:52 pm
This is a less-than-a-kilobyte clone of Lights Out.
CONTROLS
First, you will go to the main menu. Press up and down to go between menu options, and Enter to select. Press left and right to switch between modes.
In-game, press the arrow keys to move along the Lights Out grid, and Enter to turn that and all adjacent lights off. You keep going until the lights are all turned off, or you can press CLEAR at any time to quit. Either way, you will be sent back to the main menu.
MODES
The first mode is Normal mode, where all the lights are turned on.
The second mode is Random mode, where it selects a random configuration of lights.
The third mode is custom. It brings you to a screen with the grid you can customize. The controls are the same as in-game, except no special rules for switching lights apply. CLEAR goes to the game with the pattern.
CODE
Code: [Select]
Lbl S
ClrHome
"----
Ans+Ans+Ans+Ans
Disp "    SHUTDOWN",Ans," PLAY",Ans," MODE:",Ans," EXIT
3→X
1→Y
Repeat K=105
Output(5,8,sub("NORMALRANDOMCUSTOM",6Y-5,6
Output(X,1,">
getKey→K
If Ans
Then
Output(X,1,"
X+2(Ans=34 and X≠7)-2(Ans=25 and X≠3→X
Y+(K=26)-(K=24
Ans-3(Ans=4)+3not(Ans→Y
End
End
36→dim(L₁
If X=7
Goto E
If Y=3
Then
ClrHome
DelVar A1→B
Disp "
For X,1,6
Disp " OOOOOO
End
Fill(0,L₁
Repeat K=45 and sum(L₁
Output(A+2,B+1,"
rand(8
Output(A+2,B+1,sub("O*",1+L₁(6A+B),1
getKey→K
A+(Ans=34 and A≠5)-(Ans=25 and A→A
B+(K=26 and B≠6)-(K=24 and B≠1→B
6A+Ans
If K=105
not(L₁(Ans→L₁(Ans
End
End
If Y=2
Then
Repeat sum(Ans
int(2rand(36→L₁
End
End
If Y=1
Fill(1,L₁
ClrHome
"         
Output(1,10,"! SHUT "+Ans+"! DOWN "+Ans+"+------"+Ans+"!MODE: "+Ans+"!      "+Ans+"+------"+Ans+"LIGHT:"+Ans+"!
Output(5,11,sub("NORMALRANDOMCUSTOM",6Y-5,6
For(X,0,5
For(Y,1,6
Output(2+X,1+Y,sub("O*",1+L₁(6X+Y),1
End
End
DelVar X1→Y
Repeat K=45 or not(sum(L₁
Output(8,12,"
Output(8,11,sum(L₁
Output(X+2,Y+1,"
rand(8
Output(X+2,Y+1,sub"O*",1+L₁(6X+Y),1
getKey→K
X-(Ans=25 and X)+(Ans=34 and X≠5→X
Y-(K=24 and Y≠1)+(K=26 and Y≠6→Y
If K=105
Then
For(A,1,5
6X+Y
{(Ans-6)not(not(X)),(Ans-1)(Y≠1),Ans,(Ans+1)(Y≠6),(Ans+6)(X≠5
Ans(A
If Ans
not(L₁(Ans→L₁(Ans
End
For(A,X-not(not(X)),X+(X≠5
For(B,Y-(Y≠1),Y+(Y≠6
Output(A+2,B+1,sub("O*",1+L₁(6A+B),1
End
End
End
End
If K=45
Goto S
Output(8,11,0
Pause "YOU WIN!
Goto S
Lbl E
DelVar L₁DelVar ADelVar BDelVar KDelVar XDelVar YClrHome
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: Streetwalrus on November 11, 2013, 12:42:09 pm
/me sees a label in BASIC and faints
/me runs
Anyway sounds cool. ;)
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: Sorunome on November 11, 2013, 12:43:56 pm
You should try working without labels, that'll make your program better, you can like put a long while loop around it with
Code: [Select]
While K=45

[...]

End
Seeing that you have K=45 as a condition to start again.
Just an idea, though ;)
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: harold on November 11, 2013, 12:45:02 pm
How do you ensure that the random instances are solvable?
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: JWinslow23 on November 11, 2013, 12:46:30 pm
You can like put a long while loop around it with
Code: [Select]
While K=45

[...]

End
Seeing that you have K=45 as a condition to start again.
Just an idea, though ;)

I don't see how that would work. I know that labels are discouraged in BASIC, but sometimes they are the optimal solution. This may be one of those times.
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: Sorunome on November 11, 2013, 12:51:56 pm
I build my basic progs usually somehow like this:

Variables as following: for a menu, A the position, C the Keypress
Code: [Select]
Repeat A=3 and C=21  //A=3 is then the bottom-most menu item, exit
<draw menu>
Repeat C=21
<menu routine
End
If A=0
Then
<stuff for first menu point>
0->A //put cursor at the top again and prevent exiting
End
If A=1
Then
<stuff for second menu point>
0->A //put cursor at the top again and prevent exiting
End
If A=2
Then
<stuff for third menu point>
0->A //put cursor at the top again and prevent exiting
End

End
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: JWinslow23 on November 11, 2013, 12:55:31 pm
I build my basic progs usually somehow like this:
(blah blah blah code)

Now I see how it works! We just need to optimally substitute it into the program somehow. You can see how the program works, right?
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: Xeda112358 on November 11, 2013, 12:56:18 pm
I like labels in BASIC because they can often be an excellent solution and often the best solution ;)

Anyways, to answer harold, there are no unsolvable starting conditions. (Think of it like a scrambled Rubiks cube, or a scrambled knot in a string whose ends are tied together). When I made one, I wasn't sure if there were unsolvable solutions, so I just simulated n steps and presented the board.

EDIT: Oops, it seems there are some unsolvable boards for some sizes.
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: Sorunome on November 11, 2013, 12:59:36 pm
I build my basic progs usually somehow like this:
(blah blah blah code)

Now I see how it works! We just need to optimally substitute it into the program somehow. You can see how the program works, right?
I didn't really look at your code yet but I like that you use Ans a lot :D
I like labels in BASIC because they can often be an excellent solution and often the best solution ;)
[...]
When's that ??? They also have that memory bug
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: JWinslow23 on November 11, 2013, 01:00:23 pm
I like labels in BASIC because they can often be an excellent solution and often the best solution ;)

I agree with Xeda. I used labels because I thought it was the best solution.

Anyways, to answer harold, there are no unsolvable starting conditions. (Think of it like a scrambled Rubiks cube, or a scrambled knot in a string whose ends are tied together). When I made one, I wasn't sure if there were unsolvable solutions, so I just simulated n steps and presented the board.

That must have been slow, Xeda.
Harold, I did my research first, and at least for 6 by 6 grids, there are no unsolvable starting conditions. So, int(2rand(36 was sufficient.

So, was the game good?
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: JWinslow23 on November 11, 2013, 01:02:28 pm
When's that ??? They also have that memory bug

Note, he said OFTEN, not ALWAYS. That memory bug only happens if you escape out of a loop with a Lbl, and I always try to prevent that.
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: Streetwalrus on November 11, 2013, 01:03:32 pm
Hmm, try to avoid double posting please. You have an edit and a delete button at the top of your post.
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: JWinslow23 on November 11, 2013, 01:04:15 pm
Hmm, try to avoid double posting please. You have an edit and a delete button at the top of your post.
Sorry. I failed to notice the EDIT button.

EDIT: Maybe because it was labelled MODIFY.
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: Xeda112358 on November 11, 2013, 01:15:16 pm
I like labels in BASIC because they can often be an excellent solution and often the best solution ;)
[...]
When's that ??? They also have that memory bug
That memory 'bug' isn't a bug, actually, it is just misuse of Goto and Lbl inside While, Repeat, and For loops.

Examples are when you use the Menu() command, the options need to jump to labels, then if you want to jump back to the menu, you either need to use a non-optimal Repeat loop, or the more optimal Goto. For example:
Code: [Select]
Lbl 0
Menu("HEADER","ITEM 1",01,"ITEM 2",10,"EXIT",1
Lbl 01
Pause "HI!
Goto 0
Lbl 10
Pause "HAHAHAHAHA
Goto 0
Lbl 1

In reality, While loops and Repeat loops use memory (so large nestings of these can consume lots of RAM) whereas Lbl and Goto use no memory. In RPGs, using labels is usually the best option, and for games where you want to use subroutines without using subprograms, you can take advantage of mixing labels and while loops. I made heavy use of this in an RPG (http://ourl.ca/17596/325187;topicseen#new) a while ago.

To be more technical, the OS needs to push information onto an operator stack whenever it executes a loop. When it reaches an End, it uses that information and it doesn't remove it until the loop is finished. If you had 9 nested while loops, then , it pushes the data for each loop onto this stack, and when it reaches an End, the information is popped off in reverse order. If you use a Goto to jump out of a loop, the data never gets popped off the stack unless you place an unused end somewhere (but then only one item is popped off).
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: Sorunome on November 11, 2013, 01:24:17 pm
Oh, now the memory error makes sence to me O.O But isn't it the same then for multi-line if conditions?
Anyways, I prefer using loops.....
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: JWinslow23 on November 11, 2013, 01:27:16 pm
On a scale of 1 to 10, how would my game be rated?
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: DJ Omnimaga on November 14, 2013, 10:52:26 pm
Labels can also be handy if your gameplay loop is at the very start of your program and needs no variable to increment by the same value every loop iteration. In such case, Lbl is actually faster than While/Repeat. If you have a variable to increment every loop, though, then For is faster. Normally, loops made of Lbl/Goto are much slower than normal ones, but the higher the Lbl in the code, the faster the looping, and it gets to the point where at the top of the code, it can actually be faster.
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: Sorunome on November 15, 2013, 08:49:55 am
Labels can also be handy if your gameplay loop is at the very start of your program and needs no variable to increment by the same value every loop iteration. In such case, Lbl is actually faster than While/Repeat. If you have a variable to increment every loop, though, then For is faster. Normally, loops made of Lbl/Goto are much slower than normal ones, but the higher the Lbl in the code, the faster the looping, and it gets to the point where at the top of the code, it can actually be faster.
Oh, so for each goto it has to re-look through the whole code for the label? (Why doesn't TI look through the code before running it :P)
Title: Re: Re: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: DJ Omnimaga on November 15, 2013, 11:54:52 am
Labels can also be handy if your gameplay loop is at the very start of your program and needs no variable to increment by the same value every loop iteration. In such case, Lbl is actually faster than While/Repeat. If you have a variable to increment every loop, though, then For is faster. Normally, loops made of Lbl/Goto are much slower than normal ones, but the higher the Lbl in the code, the faster the looping, and it gets to the point where at the top of the code, it can actually be faster.
Oh, so for each goto it has to re-look through the whole code for the label? (Why doesn't TI look through the code before running it :P)
it starts searching at the top of the code then goes down. It stops searching once the Lbl is found. In a 15 KB program, if the label is at the very bottom, it can take nearly a second before it's found.
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: JWinslow23 on November 15, 2013, 12:57:08 pm
I see there has been much talk about labels in BASIC. I don't understand, however, that nobody has voted in the now-included poll. ???

Because there are only two labels, one to end the game and one at the very start, it wouldn't make much of a difference there. The delay of getting back to the start is nonexistent, and the delay of getting out of the program exists, but it's small. The last one doesn't matter, though, it's only getting out anyways.
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: DJ Omnimaga on November 15, 2013, 10:40:49 pm
The reason why nobody voted in the poll is because there is no download available for the game. Most people don't feel like manually copy-pasting the code in SourceCoder, let alone typing it manually on their calc, then creating a 8xp file, when the author could have provided a 8xp himself.
Title: Re: Shutdown (a clone of Lights Out Deluxe)
Post by: JWinslow23 on November 17, 2013, 07:10:27 pm
Most people don't feel like manually copy-pasting the code in SourceCoder, let alone typing it manually on their calc, then creating a 8xp file, when the author could have provided a 8xp himself.
Works for me! .8xp coming soon!

EDIT: Sorry for the bump, but I am working on an Axe version. The discussion is here, (http://ourl.ca/20212) I guess. I just need a debounce routine (and light toggling, once that's done) and it will be ready!