New Game: Circuit Puzzle

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

New Game: Circuit Puzzle

Post by Artcfox »

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.

Edit: Updated .uze and .hex files, because I moved the non-offset lock/rotate overlay icon over by 1px to center it horizontally in the green.
Attachments
circuit.uze
Updated 8/9/2020 (moved non-offset lock/rotate icon over by 1px)
(58.85 KiB) Downloaded 932 times
circuit.hex
Updated 8/9/2020 (moved non-offset lock/rotate icon over by 1px)
(164.13 KiB) Downloaded 699 times
Last edited by Artcfox on Sun Aug 09, 2020 9:19 pm, edited 3 times in total.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: New Game: Circuit Puzzle

Post by nicksen782 »

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: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: New Game: Circuit Puzzle

Post by Artcfox »

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: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: New Game: Circuit Puzzle

Post by Artcfox »

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.
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: New Game: Circuit Puzzle

Post by D3thAdd3r »

Damn, this is impressive Matt! Fun, good presentation, style, and attention to detail; great stuff 8-) Also I do like that cursor movement quite a lot, and it feels like you are moving real pieces with the PCM. Eh...trying to think of a suggestion on this polished title, but I can't think of any improvement besides possibly SNES mouse support? I did not find any bugs, and by now you have a good number of Uzebox titles to your name. Keep it up!
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: New Game: Circuit Puzzle

Post by Artcfox »

Thanks for the kind words Lee!

I have always wondered about SNES mouse support, but I don't have an SNES mouse, and either my Uzebox DTV or my Uzebox Portable is what I've been playing on these days, because the picture quality on both the Uzebox DTV and the Uzebox Portable is really good, and I don't know if there is any way to connect an SNES mouse to those. (The DTV has the connections for a P2 controller inside it.)

If, one day, I decide to do a game with SNES mouse support, I think it will have to be Plants vs. Zombies, because I think you need a mouse (or a touch screen) to collect the sunshines fast enough.

I wasn't sure if I had gotten the tuning of the cursor acceleration and friction correct, until I watched my son (who is 5) trace the path of the electricity through the circuit using the D-pad and he kept it inside the bounds of the silver wire. Maybe a Plants vs. Zombies-alike could be done using the D-pad and really big sunshines/hitboxes. The outer tiles would need to be RAM tiles for "fake transparency", while the inner tiles could just be normal tiles, unless you could pull the whole thing off with actual tiles. Hmm...

Knowing what I know now about RAM tiles, part of me wants to go and "fix up" Laser Puzzle and Laser Puzzle II because just taking a quick glance at it now, I can save so many tiles, and use RAM tiles for a bunch of the improvements I discovered with the Circuit Puzzle UI, but I already have another game idea in mind, so maybe not right now (but it would probably be a lot easier while this is so fresh in my head).
User avatar
Jubatian
Posts: 1563
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: New Game: Circuit Puzzle

Post by Jubatian »

Wow, this is nice, looks and feels very polished! Gave it a go up to Level 34 for now!

Really, so far everything to me seems to be working as expected, and intuitively does so, which is great :) The only thing I could raise that so far it feels as if the levels would always have only one solution, while so much work went into it for the game to be able to recognize a solution by simulating the circuit proper. Of course could be that there are more :) And during interacting with the pieces, it certainly acts in a solid, dependable manner, naturally, as one would expect, which feels great, a game which is very easy to pick up while giving good challenge!
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: New Game: Circuit Puzzle

Post by Artcfox »

Thanks Sándor!

The levels are supposed to have only one solution, but so far I found two solutions to circuit 31. It's a trivial change in position of the GND piece, but technically it's different from the solution printed on the solution card. And that is ignoring the different rotations of the GND piece in the cases where only one or two connections on it are used, but technically those are also different "solutions" due to the way the game is coded, where each rotation of a piece is considered a different piece.

It wasn't all for nothing though, because in all of the intermediate phases of solving a circuit (where it's actually a circuit, and didn't all get pruned away), I need to know the netlist in order to light up the proper LEDs. Also, it's possible to use the tokens on a level to make a circuit that lights up LEDs in ways that aren't part of any solution, so it needed to be general purpose, and the 27-bit netlist representation means I can store any netlist and its LED states in just 4 bytes. On top of that, I only need to store a netlist if it results in at least one LED that's on, so all-in-all, it's both quick and efficient. Any matrix netlist that has a direct short from VCC to GND automatically turns off all LEDs, so I just immediately treat it as a netlist of all zeroes, which is why the netlists are 27 bits, rather than needing 28 bits.
User avatar
Jubatian
Posts: 1563
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: New Game: Circuit Puzzle

Post by Jubatian »

Artcfox wrote: Tue Aug 04, 2020 11:43 pmIt wasn't all for nothing though...
Yup, I certainly see that, that's why the game feels so polished, that it indeed acts like electronics as you are moving about the pieces, instantenously reacting proper to the actions! It is actually especially this which makes it feel a little disappointing that mostly apart from trivial rotations of the ground piece, it seems as if levels were purposely engineered so there was exactly one solution. The game could handle cases where for example the circuit rotated 90 / 180 / 270 degrees would still be the same as an obvious case considering a blank board and a set of parts to build from.

Not a big deal, and of course could be interesting to try to find cases where actually there are multiple solutions possibly due to an oversight of the creators of the original puzzle! The game I imagine of course would accept it as solution, electrons reach their destinations, rules passed! :D
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: New Game: Circuit Puzzle

Post by Artcfox »

Jubatian wrote: Wed Aug 05, 2020 5:08 pm Not a big deal, and of course could be interesting to try to find cases where actually there are multiple solutions possibly due to an oversight of the creators of the original puzzle! The game I imagine of course would accept it as solution, electrons reach their destinations, rules passed! :D
Yes, in level 31 my alternate solution does pass (as it should, since it meets all the rules). I believe that any level that includes a "blocker" on it (bare green PCB square with nothing on it, locked to the board) would have multiple solutions to it without that blocker, and the sole purpose of the blocker is to reduce the number of solutions down to one.
Post Reply