Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: dinosteven on July 29, 2013, 10:25:05 am

Title: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 29, 2013, 10:25:05 am
Hi. I noticed Hayleia's BASIC snake game on the homescreen, and I wondered how fast it could be on the graphscreen.
Made this today while seeking Weregoose's snake game code for help. (He posted code to it a while ago, and I've used it since, but idk how to contact him about it.)
It uses a trick called the pathfinding tail eater. So no lists! :D Anyhow, here's the code, at 351 bytes:
Spoiler For the code:
::"SNAKE
:ClrHome
:ClrDraw
:AxesOff
:BackgroundOn WHITE
:120→A
:84→B
:118→D
:84→E
:26→K
:132→Xmax
:Vertical Ans
:‾Ans→Xmin
:Vertical Ans
:82→Ymax
:Horizontal Ans
:‾Ans→Ymin
:Horizontal Ans
:For(C,0,E9
:2randInt(2,128→F
:2randInt(2,40→G
:0
:Repeat K=45 or pxl-Test(B,A
:If Ans
:Then
:E+2(pxl-Test(E+1,D)-pxl-Test(E-1,D→X
:D+2(pxl-Test(E,D+1)-pxl-Test(E,D-1
:Pt-Off(D-132,82-E
:Ans→D
:X→E
:End
:Pxl-On(B,A,ORANGE
:Pxl-On(B+(K=25)-(K=34),A+(K=24)-(K=26),ORANGE
:Pxl-On(G,F,GREEN
:getKey
:If max(Ans={24,25,26,34,45
:Ans→K
:A+2(K=26)-2(K=24→A
:B+2(K=34)-2(K=25→B
:End
:If A=F and B=G
:End
:ClrDraw
:ClrHome
:Disp "SCORE:",C
Unfortunately, the snake is quite skinny due to me using pixels (necessary point-pixel usage to the pathfinding tail eater):
Title: Re: CSE BASIC Graph Screen Snake
Post by: Hayleia on July 29, 2013, 10:35:25 am
Hi. I noticed Hayleia's BASIC snake game on the homescreen
But... Mine is on the graphscreen too ???
I just use Text commands instead of pixels/points/lines because it is easier/faster.
Also, it uses lists but doesn't make any calculation on them.

Anyway, yours looks great and fast !
And the fact the snake is skinny is not really a problem on a screen sithout blur, and it gives the snake more space to move in.
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 29, 2013, 10:52:30 am
Oh lol, I thought it was homescreen from the pic. My bad for not reading your code, sorry!
Regarding lists... I don't believe it will cause a slowdown. But I'm running out of memory, after downloading every CSE program on ticalc. And each element taking up 9 bytes, something like 5,200 elements would overflow, being pixel based. (80*260/4 cuz I'm doing every other pixel). You don't have that problem because you're using text, and it can't get that big. But for the pro players on mine... ERR:OVERFLOW - so I don't use lists.
Title: Re: CSE BASIC Graph Screen Snake
Post by: Sorunome on July 29, 2013, 11:02:30 am
Looking cool! Suddenly I'm amazed how fast the CSE was, i thought it was slower, lol
Title: Re: CSE BASIC Graph Screen Snake
Post by: Streetwalrus on July 29, 2013, 12:08:03 pm
Yeah that looks pretty cool !
Title: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on July 29, 2013, 08:15:36 pm
Actually Merthsoft on Cemetech (where Weregoose can be found, by the way) made a similar Snake game (using Pt-On commands and graphics, but it had obstacles as well), but yours looks cool anyway  (and is smaller) :P

http://www.cemetech.net/programs/index.php?mode=file&id=877
(http://www.cemetech.net/img/ss/001203.gif)
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 29, 2013, 08:41:41 pm
Yeah, I actually downloaded that and another snake game before being disappointed at them using lists. imo lists are only useful temporarily due to the 9 bytes per element issue due to supporting 14 digits and imaginary numbers etc. - most of which don't get used (usually only ints are stored in them). I wish TI made it custom strings rather than custom lists.
I'm not on Cemetech, but I'll try to see if I can find Weregoose there. (Does cemetech have PMs?)
This is really just a test for speed. I'm going to test his code from 1 end of the screen to another end and multiply the time by 3 to compare with mine. (I'm pretty sure 3 should be the factor between pts to pxls). If mine is faster, I might flush it out with highscrores, making it look better, showing the score, more features etc.

EDIT: No disrespect meant to any of those authors, I swear! I just meant to that lists slow things down even though they are useful, and I wanted to make a faster version without lists, but not necessarily with all the features a list can help make. Slower doesn't mean worse, but my goal here is speed. I wasn't attacking their work at all. Sorry for coming across as disrespectful to them. :P
Title: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on July 29, 2013, 08:45:21 pm
Yeah the thing though is that lists are sometimes the only way to do something efficiently in BASIC (eg for saving in RPGs or tilemapping), but the 9 bytes per element thing is annoying, which is why tr1p1ea planned lists of 1 byte integers for some data in xLIB CSE. Strings are really slow in BASIC. >.<

(Note: I think it's wrong to insult someone's work only for using lists, matrices, pics or whatever, unless he was using ASM or Axe)
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 29, 2013, 08:55:09 pm
1 byte int lists??!!?!?!? YES. That would be great. I usually use strings because they're just so much more memory efficient - lists temporarily during execution, then I translate them into strings for long term. Int arrays of 1 byte would be a dream come true.
Title: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on July 29, 2013, 08:58:37 pm
Yeah I used strings in certain games as well, such as Illusiat 13 maps. They are only fast there because there can only be two different floor tiles to check for walking collision. Of course with 1 bytes in lists I wouldn't be able to store everything, though, such as character HP, MP, experience and gold, because the limit would be 255.
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 29, 2013, 09:02:12 pm
I've dealt with that pretty easily in Axe by using 2 bytes to store it. Just multiply the first byte by 256 and add. And voila, you have a range of 16 thousand.
Title: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on July 29, 2013, 09:05:56 pm
True, although that still doesn't solve the HP, exp and gold issue. >.< In most RPGs, experience and gold can reach 9,999,999 and some RPGs can reach 99,999 HP. I remember someone made a routine to multiply two two bytes numbers but that seemed to make it particularly confusing to dechiper the data. >.<. Damage calculations was even worse when an enemy had elemental weaknesses and your formulas used multiplications. But again even commercial console games had overflow issues anyway. :P
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 29, 2013, 10:56:45 pm
Oh wow... I would've expected numbers like 10,000, not 10,000,000. But more bytes = more space. It's a simple matter of multiplying by the base and adding. In BASIC, it's easy, right?
Title: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on July 30, 2013, 12:34:08 am
Yeah in BASIC you can pretty much use any number.
Title: Re: CSE BASIC Graph Screen Snake
Post by: tr1p1ea on July 30, 2013, 02:07:43 am
Any number that is <= 9000.

But in all seriousness, its great to see these little games coming out. It means that there is interest in the 84C and the more familiar people become with its capabilities, the more games we are going to see! :).
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 30, 2013, 09:58:37 am
lol. On another note, testing the snake going from the far left to the far right of the screen - Merthsoft was in ~10 seconds, and mine was in ~13.5 seconds. Divide my time by 3 (points to pixels) and multiply by 2 (me going every other pixel), and mine is ~10% faster than his. I've shown that lists, even when not using calculations with them, are slower than static variables. :P but ticalc needs a collection not infested by 4 times as many snake games as other games... idk should I work on flushing this out, or should I move onto other things?
Title: Re: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on July 30, 2013, 01:36:21 pm
You should probably add more features and stuff or you could just call it something like Fast Snake, so that while the game is more simple, it advertises that it's smoother and smaller, for people who want the smallest possible game. However I would suggest remaining respectful to other coders who spend their free time contributing to the community by not directly attacking their respective snake clones in your readme or something like you did a few posts above (although you can brag about your features/speed/size), else this might actually give you a bad community reputation and reduce your audience (an example is members who used to troll Omni in the past now rarely get replies to their projects). Plus, maybe your game could be taken down/flagged for innapropriate content like that (like what happened to Schoolhacker's programs).
Title: Re: CSE BASIC Graph Screen Snake
Post by: Keoni29 on July 30, 2013, 04:24:52 pm
Fancy. I remember the first calc game everyone at our school played was snake. I believe it was made in basic, but the program was protected and hidden from the editor. Great there is one for the CSE now too.
Title: Re: CSE BASIC Graph Screen Snake
Post by: Streetwalrus on July 30, 2013, 04:53:59 pm
Fancy. I remember the first calc game everyone at our school played was snake. I believe it was made in basic, but the program was protected and hidden from the editor. Great there is one for the CSE now too.
Lol that was Mario at my school. Then I went nuts with calc games and distributed a  lot to my friends and non-friends. :P
Title: Re: CSE BASIC Graph Screen Snake
Post by: Eiyeron on July 30, 2013, 05:32:27 pm
First game I saw that wasn't mine or transfered by me was a snake on Ti-82 Stats! ;)
But let's go on the topic, I have a question:

How do you do the pathfinding? Your snake doesn't move pixel per pixel, right? What's his speed? 2px/frame?
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 30, 2013, 07:30:18 pm
@DJ_O - I wasn't really attacking, just commenting that lists are slower. Of course, with a list, you can do things that my code can't do - specifically, make sure that the food isn't generated on the snake body. But personally, I don't like them for speed reasons. I was comparing to Merthsoft because his is a really good standard to compete with. No disrespect meant.
@Eiyeron - pxl tests. I move 2 pixels at a time, yes.
Title: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on July 31, 2013, 12:27:53 am
AH I see, just making sure since in your post on the other page it seemed like you thought that a snake game is completely worthless just if it uses lists, no matter how rich in features the game is, while in fact it's the most efficient way (although not speed-wise) to do a snake game when it comes to collision detection (even moreso if you use the home screen, where pxl-test collision is impossible). There were people in the past who said that any calc game that uses more than one file is a total piece of garbage, no matter if the coder had the choice or not (for example, good luck making a BASIC Pokémon that doesn't suck using one single program, no list and no pic). >.<
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 31, 2013, 12:31:46 am
Haha no, I'm not one of those people. Any piece of code that an author worked hard on is worth a lot, even if it's just a Hello world prog or another quadratic formula.
Title: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on July 31, 2013, 12:39:10 am
Well I would probably not say that Hello World is very worthy of download, but if it helped the coder learn it's good, and hopefully he makes better programs eventually.
Title: Re: CSE BASIC Graph Screen Snake
Post by: Hayleia on July 31, 2013, 02:03:30 am
How do you do the pathfinding?
If I understand the code correctly, for each frame, he gets the new coordinates of the tail by pixel-testing around the old coordinates of the tail (so he can erase the old coordinates for this frame and he has the new ones for the next frame).
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 31, 2013, 09:58:44 am
Absol-utely correct! It should be noted that the idea for this pathfinding tail eater didn't come from me... it came from Weregoose. I simply coded it.
Title: Re: CSE BASIC Graph Screen Snake
Post by: Eiyeron on July 31, 2013, 07:30:45 pm
Clever thing. (Casio calc have a very slow Pxl-Test, so we program without it)
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 31, 2013, 07:45:26 pm
Yes. The information already has to be on the screen, so you might as well access that information rather than create a second database of information.
 What's the resolution of your Casio calc? If it's very large, that may have something to do with the slow testing. idk
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 31, 2013, 09:00:54 pm
Update - added a pause function and it now displays the screen. Also, I actually looked at Weregoose's code and found a few optimizations I could make, while getting this from him:
Quote
Based on a program written by Weregoose from http://www.cemetech.net

That in the program description would make me happy.
So I added it as a comment to my code, adding bytes to the size to 512 lol. I'll upload it when I find my cord.
Title: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on July 31, 2013, 09:33:17 pm
Yes. The information already has to be on the screen, so you might as well access that information rather than create a second database of information.
 What's the resolution of your Casio calc? If it's very large, that may have something to do with the slow testing. idk
I think it's a glitch or Casio really screwed up. When using a drawing command (no matter which one), there is a 0.3 second delay before it appears. The LCD is not that much larger than the CSE and the processor is actually faster.

Update - added a pause function and it now displays the screen. Also, I actually looked at Weregoose's code and found a few optimizations I could make, while getting this from him:
Quote
Based on a program written by Weregoose from http://www.cemetech.net

That in the program description would make me happy.
So I added it as a comment to my code, adding bytes to the size to 512 lol. I'll upload it when I find my cord.
Yeah this might be a good idea (as it is whenever you re-use some code or inspire yourself greatly from it or the program). I would recommend moving this to the readme or program description rather than comments, though, because BASIC comments slows down program execution (since it stores a string to Ans)
Title: Re: CSE BASIC Graph Screen Snake
Post by: dinosteven on July 31, 2013, 09:36:15 pm
Yeah, I was intending to, but I wasn't sure how he liked to be credited.
Title: Re: Re: CSE BASIC Graph Screen Snake
Post by: DJ Omnimaga on August 01, 2013, 12:15:44 pm
Generally we just follow the original authors' credit rules, if any, then if we re-use source code we have to make sure the original author allows us to, then we just mention him in our readme and if lots of code is used, game. Then if they're not happy about it we follow their instructions.