Page 1 of 1

Threes

Posted: Wed Apr 16, 2014 7:43 am
by Schlowski
(Split out of 2048-thread)

Simple working version of Threes for unexpanded VIC, pure basic, now at least with some optimizations and eye candy :D
Should run with any memory configuration as it's only BASIC and PRINTs...

Move tiles with WASD or IJKM or cursor keys

Game in progress:
Image

Final score (Scoreboard):
Image

Final score (Playfield):
Image

Program: http://www.stojalowski.de/files/Threes.prg

TODOs:
nothing - run out of space :-)

As I could not find any "official" rules for playfield randomization and new tiles I simply invented my own rules. Seems to be a little bit harder than the original, but there are some nice scores possible.

Any comments are welcome 8)

Edit: Finished work on this one, implemented a simple hiscore list and optimized stratup a little bit. After running 2 rounds there about 60 bytes free memory left...

Re: WIP: Threes

Posted: Wed Apr 16, 2014 8:36 am
by Schlowski
Working like a charm, after some rounds here's my best score so far:

Image
Image

At the beginning of this project I was a little bit worried about the more comfy speed of the VIC version, but now I'm quite used to the pacing. This leads to some more thinking before shifting the board mindlessly around :roll:

Re: WIP: Threes

Posted: Sat Apr 19, 2014 3:34 pm
by Vicman *1970
Hi,
what are the rules on this game ? (translate/say it also in german please :wink: )

Re: WIP: Threes

Posted: Mon Apr 21, 2014 9:08 am
by Schlowski
You can shift the playfield left/right/up/down. If numbers collide they combine if they are
a) a 1 and a 2 giving a 3 or
b) two identical numbers 3 and above resulting in the sum of them, e.g. 3 and 3 giving 6, 24 and 24 giving 48 etc.
Each move a new number will be shifted in.
There's more, but you will figure it out when playing, especially when which numbers combine and where and which numbers will be shifted in :-)

German:
Du kannst das Spielfeld links/rechts/hoch/runter schieben. Wenn zwei Zahlen aufeinandertreffen werden sie kombiniert, wenn
a) es eine 1 und eine 2 ist, das wird dann eine 3 oder
b) wenn es zwei identische Zahlen größer gleich 3 sind, dann ergeben sie die Summe, d.h. 3 und 3 ergeben 6, 24 und 24 ergeben 48 usw.
Bei jedem Zug wird eine neue Zahl ins Spielfeld geschoben.
Es gibt noch mehr Regeln, aber die findest Du beim Spielen raus, besonders, wann welche Zahlen nun tatsächlich kombiniert werden und wo und welche Zahlen nachgeschoben werden :-)

Re: WIP: Threes

Posted: Mon Apr 21, 2014 12:55 pm
by Vicman *1970
Thanks for the Info !
I'll give it a try.
Don't forget to post, when you have finished the developement.
So i can add this to TOSEC and FE3-Card Collection :wink:

Re: Threes

Posted: Tue Apr 22, 2014 4:14 am
by Schlowski
Finished, added a simple hiscore list and made some final optimizations on the starting grid.
No more space left, had a lot of "out of memory" errors during implementation, hopefully now it's on the right edge of the memory cliff :shock:

After playing 2 rounds I had 61 bytes left which seems to be as low as it can go without the interpreter to complain about memory.

Re: Threes

Posted: Tue Apr 22, 2014 11:23 am
by Vicman *1970
O.K. Thank You
One question : For TOSEC-Naming. Should i use your Nick- or your Realname ?
If realname you can send me a PM here or over at Forum64.

Re: Threes

Posted: Wed Apr 23, 2014 12:31 am
by Schlowski
Nick is ok, thanks.

Re: Threes

Posted: Wed Nov 19, 2014 1:50 am
by wimoos
Hello Schlowski,

I have optimized the Threes game in WimBasic. I managed to bring it down to less than 2500 bytes (and less than 70 program lines), using not only the features that WimBasic offers (like SWAP and INSTR) but also some standard Basic memory saving techniques. Bringing all variables back to one letter instead of two is one of them.

A nice one that I found is your use of: int(3^(log(X)/log(2)). In this formula X and 3 are commutative, so that it can be written as int(X^(log(3)/log(2)).
You can isolate the constant factor of log(3)/log(2), so that it comes down to int(X^P). In this formula, when X is zero, the result is zero (your formula bounces on LOG(0)).
Hence you can take out the preceding IF X=0 condition to make the rest of the code generic :D .

Another one is where you check one cell for the value of 1 and the adjacent for the value of 2, while on the following line you check for the values 2 and 1 respectively, and the clauses in both lines are the same. Both lines can be taken together by multiplying both cells and compare the result to 2.

Regards,

Wim.

Re: Threes

Posted: Thu Nov 20, 2014 1:13 am
by Schlowski
Hi Wim,

nice work on math optimizing :D
Another one is where you check one cell for the value of 1 and the adjacent for the value of 2, while on the following line you check for the values 2 and 1 respectively, and the clauses in both lines are the same. Both lines can be taken together by multiplying both cells and compare the result to 2.
That one is so obvious, thanks for pointing out, I don't know how I could have missed it.

Regards
Schlowski

Re: Threes

Posted: Mon Aug 01, 2016 2:18 am
by wimoos
Hello Schlowski,

I brought it down further (in WimBasic of course :-)) to 53 lines and 2274 bytes.

An interesting technique I now used (that can also be done in CBM basic) is redefining functions. I applied that to the display routine, where during play the P% matrix is referenced, and variable colors.

Code: Select all

DEF FNC(X)=-3*(3<X)-X*(X<=3)    (or =MIN(X,3))
DEF FNV(I)=P%(X,Y)
During game result the W% matrix is referenced and one fixed color.

Code: Select all

DEF FNC(X)=1
DEF FNV(I)=W%(X,Y)
I also defined a function for calculating the next (random) value. For this you need an extension like WimBasic:

Code: Select all

DEF FNB(X)=B%(RND(MIN(X,MAX(X*ROUND(RND(1)),3))))
And I used PRINT USING to build up the field on the screen without the hassle of RIGHT$(STR$()),4) etcetera. It gives a more fluent result.

Regards,

Wimoos.

Re: Threes

Posted: Tue Aug 02, 2016 12:17 am
by Schlowski
Hi Wimoos,

nice little additions, especially the trick with redefining functions. It never occurred to me that this was even possible, I think that is a result of years using compilers which are more static in that respect :-)

I'm a little bit in hibbernation regarding the good old VIC right now, but when the time comes and my interest in VIC computing rises again I will definately have a closer look on WimBasic. You made a great enhancement to the basic (as in simple) interpreter!

Regards
Schlowski