New Game: Circuit Puzzle

Use this forum to share and discuss Uzebox games and demos.
Post Reply
User avatar
Artcfox
Posts: 1011
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

New Game: Circuit Puzzle

Post by Artcfox » Sat Aug 01, 2020 6:28 pm

After a bit of a hiatus, I've completed my fourth game!

It's a Uzebox implementation of a physical board game that my kids and I would like to play, but most of the time the pieces do not make proper electrical contact with each other, so trying to play the physical game is almost impossible. Therefore, I needed to turn it into a Uzebox game before we could enjoy it.

Image

For each circuit, arrange the tokens to form a continuous pathway from VCC to GND that lights up the designated LEDs. All tokens must be used, and there can be no loose ends, except on the SWITCH and GND tokens. There is a built-in rule checker to help. The normal rules of electrical current and LEDs apply. Avoid creating short circuits.

After solving a circuit, you can choose to move on to the next circuit, or you can continue experimenting with the tokens on the solved level.

Features
  • 60 levels: Beginner, Intermediate, Advanced, and Expert
  • Background music
  • 6 PCM sound effects
  • Context-sensitive help
  • Built-in rule checker
  • Quick netlist-based circuit "solver"
  • Mouse pointer acceleration (for precise movement)
  • RAM tile-based popup menu
  • Uses EEPROM to track progress
  • Unlock secret ending when all circuits have been solved
The implementation ended up being trickier than I expected, but I eventually figured out how to fit it all onto the Uzebox. I used Mode 3 non-scrolling for the video mode, but this time I used Jubatian's RESOLUTION_EXT so I could cram more horizontal pixels onto the screen. I made extensive use of RAM tiles, because I was severely constrained by the tile limit. There is a context-sensitive help section in the bottom right corner of the screen, so you'll always know which buttons you can push at any given time to manipulate the tokens. I didn't want to compromise on the look of this context-sensitive help, so that's what ended up blowing my tile budget. The mouse cursor uses a sub-pixel, fixed-point physics model to keep track of its acceleration, so its motion can be controlled very precisely if desired. I hesitate to even mention that, because if it's done right, you shouldn't even notice it.

If you press the START button during the game, you'll get a nice popup menu that allows you to reset the tokens, switch circuits (and see which ones haven't been solved yet), and toggle the music on or off. I added a brief "How to play" section, which you can access from the title screen, and I also added a built-in rule checker that ensures you solve each puzzle correctly using all the tokens, without any short circuits, and no "loose ends" (on pieces that can't have loose ends).

Image

Knowing myself, I made sure to completely finish up the framework and UI before I even started working on the solver (though to be completely honest, it was mainly me procrastinating while trying to figure out how to create the solver). The solver looks at the board, prunes or "degenerates" any pieces with loose ends, and then sends out "electrons" from the pieces of interest still left on the pruned board in order to build up a matrix that represents the netlist. I then convert this matrix into a 27-bit number which represents the entire circuit. Once I got to a point where I could arrange the tokens on the board and have the whisper console spit out a netlist, I tediously arranged the tokens to build as many different circuit configurations that I could think of (that result in at least one lit LED), and then manually combined each 27-bit netlist with the correct LED on/off bits. I then ran each of those combined netlists and LED on/off states through a program that generates all possible permutations of those netlists with the LED colors swapped around. This more robust set of netlists and LED on/off states is then sorted by netlist, and stored in flash memory where a binary search can be performed on it whenever the board changes.

Instead of randomly deciding which direction to go when hitting a branch (like my Laser Puzzle games did), this game systematically chooses branches so it can generate a netlist in far fewer iterations. I use the EEPROM to store which circuits have been solved, and I included an "epic win" screen that you can unlock by solving all 60 puzzles. I generated my own "Tada!" sound by arranging notes in Rosegarden, and then rendering that MIDI to a WAVE file with various different instruments until I found one that sounded good when the PCM was resampled down for the Uzebox. I also discovered a great book called Arcade Game Typography, so I was able to really step up my font game (no more blocky ATARI font!). I included a bunch of different PCM sound effects (6 in total), and again I tediously transcribed a song frame-by-frame from a YouTube Synthesia video and arranged it using Rosegarden. Since I was forced to use so many RAM tiles, I was also able to use a bunch of RAM tile effects, like smoothly fading certain text in, single pixel-level manipulation of the RAM tiles, faked "transparency" in certain spots, etc...

Many thanks to CunningFellow for his suggestions throughout the development process, for being my sounding board, and for helping me test out various iterations of the game. And thanks to everyone for providing feedback on my previous games. I tried to address as much of that feedback as possible during the creation and polishing phase of this game.

Wiki entry for the game: http://uzebox.org/wiki/Circuit_Puzzle

If anyone ends up building a circuit where an LED isn't lit up when it should be, please let me know via screenshot or photo, and I can easily add it to the database.
Attachments
circuit.uze
Updated 8/3/2020
(58.85 KiB) Not downloaded yet
circuit.hex
Updated 8/3/2020
(164.13 KiB) Not downloaded yet
Last edited by Artcfox on Mon Aug 03, 2020 8:09 am, edited 1 time in total.

User avatar
nicksen782
Posts: 686
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: New Game: Circuit Puzzle

Post by nicksen782 » Sun Aug 02, 2020 3:59 pm

Awesome! A new Uzebox game!

I added a link to the online play into your wiki entry. (https://nicksen782.net/UAM/APP_emu/emu.php?gameid=275)

I look forward to playing this game some more! I would be interesting in you describing the technical portions of your game.

User avatar
Artcfox
Posts: 1011
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: New Game: Circuit Puzzle

Post by Artcfox » Sun Aug 02, 2020 4:56 pm

Thanks, and thanks for adding it to the online player!

Do you mean like a deep-dive into certain technical aspects? That could make for a cool YouTube video where I re-enable certain debug #defines, recompile the code, and run it in the emulator while I do a voice-over of what is happening.

There is a section of defines at the top of circuit.c that will change the behavior of the code. One will take over the GOAL section of the breadboard and use it to display what the pruned board looks like, another will print out the matrix netlist over the whisper console, another the 27-bit representation of that matrix. I did put in stubs for tracing out the path of the "electrons" that the solver sends out from each "piece of interest" (vcc, red anode, red cathode, yellow anode, yellow cathode, green anode, green cathode), but it worked without me ever needing to debug it, so I never ended up making a visualizer for it, but I left those stubs in there (commented out). That path tracing mechanism is the same one that I used for tracing the path of the laser in the Laser Puzzle games, but it wouldn't make sense to show it all at once at the end, because the pathways that it finds would always match where the wires are in the pruned board.

I would have to have it pause at each iteration of the loop and overlay in/out arrows on the token where the electron currently is. That could actually be pretty cool! When it finds another "piece of interest", it terminates that electron and adds the source and destination pieces to the netlist matrix. For each of the "pieces of interest" I listed, it sends out a total of 8 electrons, with each programmed to take a different sequence of branches (if encountering a branch). If there aren't any branches, some electrons will end up finding the same piece again.

If an electron ever ends up in a loop, there is a TTL that is decremented every time it moves into a different token, so that electron will eventually "time out" and the simulation will continue with the next electron that is programmed to follow a different sequence of branches. So if you wanted to watch the solver generate the netlist for a given circuit, you'd have to step through the path of 56 electrons. I could have done "loop detection" but I think that all of those if/else statements at every step of the way would have been slower than just letting an electron loop until the TTL expires it (and it would have bloated the code).

User avatar
Artcfox
Posts: 1011
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: New Game: Circuit Puzzle

Post by Artcfox » Mon Aug 03, 2020 8:24 am

After explaining how that works, I realized an easy optimization that I should have been doing. If an electron finds another piece without hitting a branch, I don't need to send the other 7 electrons down that same path, because they won't find a branch either. That saves a ton of clock cycles when BoardChanged() is called (13000+ on level 55 with the switch in the 3rd position, but 3000-4000 typically). I also realized a few other optimizations, both in size and speed, found and fixed a bug if you pressed and released START exactly between successive reads of the Joypad when the PRESS START FOR NEXT CIRCUIT text was fading in, and found and fixed a bunch of single-frame sprite/RAM tile glitches that you could only see when single-stepping the screen transitions inside cuzebox. I also added a bunch more comments in the code.

The latest update is now re-attached to the first post.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests