r/programminggames • u/ikamusume11964 • 6h ago
I am having fun with Hello Triangle: my zachlike circuit building game
TL;DR: I tried to be creative to find a solution that beats the intended solution in my game Hello Triangle: Build a GPU, and I'm having a lot of fun.
Recently I made an update to my game Hello Triangle: Build a GPU, that added score histograms to the three metrics each level is rated.
The last level of act 1 asked player to build a rasterizer to draw a triangle. The intended solution is to find the bounding box of the triangle, and scan through every pixels in the bounding box. I believe this is called bounding-box rasterization.
However, the game doesn't require you to build for a specific solution. The game simulates your circuit, see what's rendered and compares it to the goal to check for correctness. As a result, I can build a solution that costs even less cycles by scanning only the pixels in the triangle, and there is an algorithm for exactly that called scanline rendering.
So I set myself to wire the scanline algorithm, sorting the three points, splitting the triangle, calculating the inverse slope, sweeping the horizontal lines. The in-game notepad helped a lot and I didn't have to grab a pencil and paper to calculate. In the end, I got a big circuit and here's a part of it:

And when I run it, viola! I got a new best score of 370 cycles. The cycle score represents the number of cycles required to pass the 4 public tests for this level, and 370 is still above the number of pixels in those 4 triangles in the tests, so there is still room to improve the solution even further. On the other hand, the area and delay of this solution is much bigger than the intended solution as I have to create a big circuit to make the algorithm work.

It gave me a big sense of achievements passing this level with the scanline algorithm after spending 2 hours tring to debug this solution, and I had a lot of fun. I hope the game can bring the same fun to you, and maybe you can beat my score of 370 cycles! The demo is available on Steam and the Steam store page is https://store.steampowered.com/app/5395930/Hello_Triangle_Build_a_GPU/, if you would like to give it a try!

