After recently rebuilding Torch in ASCII using Phoenix and Elixir, I was inspired to do it yet again but with the original ray-casting-on-canvas look.
This is a super-simple express server with websockets and in-memory state. The more complicated multi-player raycasting makes a return this time though (no list comprehension shortcuts when we're doing it this way, unfortunately.
I still think there's some fun to be had in this game and maybe in another 15 years or so, I'll rebuild it again.
I was looking for an excuse to play with Elixir and Phoenix and decided the best thing to do would be grabbing an old idea and throwing some new tech at it.
And, to mix things up, why not restyle it to look like a very old idea?
Using ASCII for this meant that I could actually do a lot of the visibility and ray casting using simple list comprehension (i.e. intersect all other player's 'lighted' cells with the current player's 360 ray cast visibility)
The performance on the deployed version isn't great due to network latency. Essentially, the game ticks every 100ms and sends an update to each player so if you're moving left then press down, typically the server will process one more left event before your down arrives. There are plenty of blog posts about handling latency, not just in multiplayer online games but also specific discussions on multiplayer online snake. I decided I could either dig into refreshing my knowledge of that or stick with refreshing my knowledge of Elixir and Phoenix. I went with the latter.
The aim is to get the highest number possible after using each of your tokens.
There is 1 die
Each player has 4 tokens with different symbols on:
+−×÷
Each player rolls the die and the number they get is their starting number.
Lowest score starts. If there's a draw, youngest of those starts.
Each round:
Roll the die
Choose one of your operations.
Perform your operation with the new number and your existing number. Try to get the highest score
Discard your operation token. You only get to use each operation once.
Note: When the calculation is a division with a remainder, you can either discard the remainder or continue with decimals, depending on who is playing.
Example game:
2 players.
A rolls 2, B rolls 3. A has the lowest starting number so they start
Round 1
A rolls a 4. They decide to use their + operation. They now have 6.
B rolls a 1. They use their ÷ . They still have 3.
Round 2
A rolls 6. They use their × . They have 36.
B rolls 5. They use their × . B now has 15
Round 3
A rolls another 6. They've already used their × so they have to either subtract 6 or divide by 6. They use − . They have 30
B rolls 2. They + it. B has 17
Round 4
A rolls another 6! Now they only have their ÷ left. They have to divide 30 by 6. Now they have 5.
B rolls 3. They have their − left. B has 14.
B wins.
Variations
For advanced maths, add in the power and root symbols ^√
Try to get the lowest score instead of the highest.
Try to get the lowest score without going below zero.