This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic Brain Teasers => TI-BASIC
Author Message
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 05 Apr 2007 01:18:05 am    Post subject:

Create the smallest dodge the asteroids game. In this game your ship "V" is on one end of the screen while the asteroids "*" randomly come from the opposite end of the screen. The asteroids are continuous and there is one per row. Think of this as an Avalanche game except the asteroids don't have to fall in the down direction (hint: think up)

The one I have is 107 bytes, but I think there is still room for optimization.

The game has to be error free as well. Meaning you won't get an ERROR:Domain if you move the V past the limits of the screen. (Just had to say this because it is actually possible to make the game in 90 bytes if you allow errors)


Last edited by Guest on 05 Apr 2007 10:08:02 am; edited 1 time in total
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 05 Apr 2007 09:30:03 am    Post subject:

Not quite what I had in mind. I'll update the brain teaser to make it more clear.

Let me just say that the one I have doesn't have a score or anything.
I left out all the fancy stuff in order to make it small as possible.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 05 Apr 2007 12:19:12 pm    Post subject:

I have 106 bytes, but I'm not ready to give up on it as being fully optimized either. You can cut it down several more bytes by using a list such as LX instead of L1, but that's more messy in my opinion unless you delete it at the end (losing those bytes again).

Edit: 103 bytes (optimized key-reading a bit). I wonder if I can get it to below 100.


Last edited by Guest on 05 Apr 2007 12:29:53 pm; edited 1 time in total
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 05 Apr 2007 12:43:20 pm    Post subject:

103!? That's amazing! How did you do it?

I don't want to spoil the fun for everyone, but here is what I had:
Spoiler wrote:
For(X,1,7
Disp "(without a space)
End
DelVar L1Repeat X=Ans(7
getKey
X+(Ans=26 and X<16)-(Ans=24 and X>1->X
Output(1,Ans,"V
6->dim(L1
augment({randInt(1,16)},L1->L1
Output(8,Ans(1),"*
Disp "(without a space)
End
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 05 Apr 2007 12:56:31 pm    Post subject:

My solution:
spoiler wrote:
binompdf(6,0→L1
For(X,1,7
Disp " (without a space)
End
Repeat X=L1(1
getKey-25
max(1,min(16,X+Ans(2>abs(Ans→X
Disp " (without a space)
Output(1,X,"V
randInt(1,16
Output(8,Ans,"*
ΔList(cumSum(augment(L1,{Ans→L1
End


Last edited by Guest on 05 Apr 2007 12:56:50 pm; edited 1 time in total
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 05 Apr 2007 03:50:57 pm    Post subject:

Eureka! I have come up with a under 100 byte version.

So basically I combined the two ways and got this:

Code:
DelVar L1For(X,1,7
Disp "(without a space)
End
Repeat X=Ans(7
getKey
max(1,min(16,X+Ans-25not(not(Ans→X
Output(1,Ans,"V
7→dim(L1
randInt(1,16
Output(8,Ans,"*
augment({Ans},L1→L1
Disp "(without a space)
End

By changing the key-reading routine I was able to save 2 bytes, but as a result, the "V" will sometimes move more than 1 space if keys other than the arrows are pressed. It doesn't cause errors though.

So right now, the code is at 98 bytes with the strange key-reading routine.
With Darkerlines key-reading routine it works correctly, but with the addition of 2 bytes.

By the way Darkerline, I have never seen such compact routines for key-reading and list shifting before. In fact, I didn't even know that a compact method existed for shifting the values in a list up. ΔList(cumSum(augment(L1,{Ans→Awesome!
Back to top
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 05 Apr 2007 04:01:01 pm    Post subject:

Gahh!

OK, my teaser. Instead of the smallest, go for the fastest. Make and Avalanche game under 500 bytes that has a losing message and scoring. (No high scores required).

My solution is in the xPegz topic Smile.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 05 Apr 2007 05:23:11 pm    Post subject:

To start this off with something to improve on, here's the above code modified for Harrierfalcon's conditions:

Code:
DelVar SDelVar L1For(X,1,7
Disp "(without a space)
End
Repeat X=Ans(7
S+1→S
getKey
max(1,min(16,X+Ans-25not(not(Ans→X
Output(1,Ans,"V
7→dim(L1
randInt(1,16
Output(8,Ans,"*
augment({Ans},L1→L1
Disp "(without a space)
End
ClrHome
Disp "You lose!","Score:
S

To time how fast the game is, start a stopwatch, play the game for a while, stop the stopwatch when you lose, and divide the score by the time to get FPS. The above game runs at about 4.3 frames per second on my calculator.
Back to top
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 05 Apr 2007 05:33:44 pm    Post subject:

I get a little faster than 6.75.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 05 Apr 2007 05:44:32 pm    Post subject:

I get 8.25 (or so) from combining the ideas of the programs here and Harrierfalcon's. I also managed to get 5.7 from the list approach.

I'm currently looking at something really crazy...
Back to top
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 05 Apr 2007 05:47:29 pm    Post subject:

Which is?

Oh, instead if [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]randInt(1,16
it's been proven that [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]1+int(16rand) is not only smaller but faster too.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 05 Apr 2007 05:59:24 pm    Post subject:

I'm trying to store all the asteroid positions in a single number rather than in 8 (or 7). Unfortunately, my calculator seems to be messing with my head.

Also, we should try to keep in mind that these frame-per-second dealies don't transfer between calculators very well (one of ours could well have low batteries, or be a different model with a slower screen or some such, not to mention if you're using a SE or an 84+).

Also, ignore the 8.7 I found earlier, that's a bogus result.

Wait.. do you want the screen to go down instead of up? If so, that's a different game than the previous teaser.


Last edited by Guest on 05 Apr 2007 06:04:23 pm; edited 1 time in total
Back to top
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 05 Apr 2007 06:10:16 pm    Post subject:

Down. Like icicles falling on someones head.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 05 Apr 2007 06:12:44 pm    Post subject:

Yeh, well in that case my way doesn't work any more because you have to keep track of all the objects all the time instead of just the first and last.
Back to top
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 05 Apr 2007 06:25:35 pm    Post subject:

Mine is 255 bytes and gets about 6-7 fps. Anyone beating me?
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 06 Apr 2007 02:44:26 pm    Post subject:

Well, apart from the usual replacing of variables with finance variables, I've got nothing.

I did however make a pretty fast dodge the asteroids game:
[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]0→I%
0→PV
0→N
8→PMT
For(X,1,7
Disp "
End
Repeat PMT=1+16fPart(PV
1048576I%+.0625int(PV→PV
getKey-25
max(1,min(16,PMT+Ans(1=abs(Ans→PMT
int(16rand→I%
Disp "
Output(1,PMT,"V
Output(8,I%+1,"*
N+1→N
End
ClrHome
Disp "You lose!","Score:
N


Around 180 bytes (depending on the name). My high score is 1003.

Edit: I did find an optimization: you can write your own random number generator instead of using the built-in one. In Harrierfalcon's program, it would go something like
[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]If S<8:Then
int(16rand→H
Else
int(16fPart(BAD/31→H
End

Except of course I'd actually have to put some thought into making up an operation that wouldn't end up converging to something predictable after playing for a while.

This does make a noticeable speed difference, though, because [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]rand is so slow.

Last edited by Guest on 09 Apr 2007 03:28:49 pm; edited 1 time in total
Back to top
Display posts from previous:   
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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement