Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
  You are not logged in 
Mathsticks10   [2021]

Mathsticks10 Released by :
Commocore [web]

Release Date :
18 June 2021

Type :
C64 Game

Website :

User rating:awaiting 8 votes (8 left)

Credits :
Code .... Bago Zonde of Commocore, FanCA

Download :
http://csdb.dk/getinternalfile.php/215310/mathsticks10.prg (downloads: 16)

Look for downloads on external sites:

Submitted by Bago Zonde on 16 July 2021
This game was written for ASCII Basic Game 10Liner competition 2021.

It's inspired by classic quiz games I remember from some newspapers and also just from several matchboxes.

Aim of the game
Try to solve as many equations as possible, and as quickly as possible!

Find the right equation by moving one match from one place to another only.

Signs of the equation cannot be changed, you can modify numbers only.

You have to enter the first digit, followed by the second one and the result of the addition.

When the correct answer is provided, you earn a point and progress to the next equation.

Otherwise game ends. Then, you will see the number of points scored and how long have you played in seconds. The highest score is the best one only if scored in the shortest time, this is what all champions aim for!

When the program runs via emulation with autorun, randomisation doesn't work properly. On each run, all numbers are returned in the same sequence without the user's interaction (explanation here).

In order to avoid this behaviour, break the execution of the program on run with ESC key, and type RUN followed by ENTER to start the game again. From now on, the sequence will be randomised.

Coding challenges
What makes this challenge harder, was not only that a program has to fit in ten lines but also in the 72 characters per line limit. Because of that, I played with different ideas and in the end, I created four versions including a different approach of locating matches on the screen, numbers randomisation, and answer validation. This involved a lot of commands swapping to squeeze them in a single line and finding some patterns after writing a portion of code to make things clever. Or, just shorter, as I still think there is a way to make this code more clever! There must be, right? It was some sort of a question about the infinity of possible solutions against the finite amount of lines available.

The simplest trick I used was to spread variable initialization by using READ and DATA. Iteratively I needed to move things to different lines and see if it fits. Lots of swapping, and saving of the character space like the one with the most common numbers occurring in the game. "10" takes two places, but when assigned to a "Z" variable, it takes one!

To save some character space I also defined a function for randomisation which saved just a few characters, but a few I needed.

Another idea to save some characters space was to define the graphical representation of all matches not within DATA but with printing values as PETSCII characters on the screen.

I used the same colour as the background to print them, so they are not visible but you can find them on the very top of the screen. So, instead of using an array that needed to be assigned from DATA values, PEEK was used to read data from the screen.

As the space available is really small, code is not able to replace one match ahead before drawing all matches on the screen. It might happen then, that during the rendering of the equation, a match taken from one place cannot be moved to another. In such situations, I added a fallback to re-shuffle an equation which will cause also a redraw of the screen. Not a big deal, but I really had no free space to write some sort of a dry-run or provide some fixed possibilities.

One of the earlier versions had a naive approach of accepting an answer as a correct one only when the first and the second digit were exactly the same as the numbers randomised by the program. What could happen though is that when the program randomises that 2 + 3 = 5 and the player provides 3 + 2 = 5, it would be treated as an incorrect answer?! Everyone knows that addition is commutative, meaning that order does not matter. So the program needed to behave the same way. But there was no free space left. 10 lines of code taken already!

Moving a match with some pointer rather than providing values from the keyboard would be a perfect solution. The program would only need to check then if the shapes of all matches are referring to numbers, but again, there was no space left! Using INPUTs instead is just the shortest.

It seemed that the project cannot be finished, but I knew there must be a way. And I found one by having a eureka moment during some random walk. What I realized was that to solve this problem I have to think about the BALANCE. When one match goes somewhere else, the balance is still there so the program has to validate the player's input to see if the amount of matches is the same and that the equation makes sense. Of course, under some circumstances, there is room for some other answers, but it's rare. This way I saved a lot of space by re-using the same code which already renders matches on the screen to add another dimension to it: to not render but count a number of matches provided from the player's equation. This solution saved the project!

In the end, I learned that when autostarting the game you'll get the exact same seed every time the game runs. As the result, all equations were not random at all but followed the same sequence each time the game ran! It's caused by no user interaction. I managed to fix it by calling RND(-IT) but in the case the game is executed with autorun via emulation, this behaviour can be fixed by breaking the execution and running the program again.
Search CSDb
Prev - Random - Next
Detailed Info
· Summaries (1)
· User Comments
· Production Notes
Fun Stuff
· Goofs
· Hidden Parts
· Trivia
· Discuss this release
Sponsored links
Support CSDb
Help keep CSDb running:

Funding status:

About this site:
CSDb (Commodore 64 Scene Database) is a website which goal is to gather as much information and material about the scene around the commodore 64 computer - the worlds most popular home computer throughout time. Here you can find almost anything which was ever made for the commodore 64, and more is being added every day. As this website is scene related, you can mostly find demos, music and graphics made by the people who made the scene (the sceners), but you can also find a lot of the old classic games here. Try out the search box in the top right corner, or check out the CSDb main page for the latest additions.
Home - Disclaimer
Copyright © No Name 2001-2021
Page generated in: 0.083 sec.