Once again a depressing amount of time has passed since my last update. Given what's on my plate workwise over the next few months I suspect the sporadic nature of my posts will continue. Thankfully I have continued to find time to chip away at the game, and some progress has been made.
After I managed to get a super rough first pass of the (very) initial base of the game done (with the balls/bubbles/whatever falling down the board and stacking up correctly), the next thing to tackle was the colour matching. This ended up being a rather humbling endeavour as my initial confidence met the realities of my inexperience with 6502 coding.
The first step was get the connecting neighbours for each any given cell on the board, which was straightforward enough.
With a simple routine to return a list of neighbours for a given cell, I could move on to figuring out all of the matching connected items. This is where things got a little complicated. The board on which the items appear can be viewed as a graph/network of connected nodes. Most nodes have up to 6 neighbours, whereas those on the edges & corners of the board have up to 2, 3 or 4 depending on their position. Chains of connected items can potentially use every cell on the board. So I decided to use a basic graph/network search, which looks something like ...
For a given item:
- Push the item onto the "open" stack (items that need to be visited)
- While the open stack has items on it:
- Pop an item
- Mark it as matched & visited
- Get a list of matching neighbours
- Iterate through each neighbour, and if they haven't been visited then push them onto the open stack.
- Go to step 2
While this is the kind of thing I've done many times in more fully featured languages, I really struggled to get my head around doing it with 6502. The fact that I didn't have decent chunks of time to sit down and focus on it didn't help. I eventually got there, though, and the moment where it finally worked was one of the most satisfying achievements for me in recent times, which is somewhat amusing.
What this all highlighted for me was that I really needed to spend some time improving my testing and debugging process. The C64Debugger was useful, though I just can not seem to get it to load symbols - I keep meaning to download the source and have a poke around. I had never really explored debugging in VICE, but I found this blog post a great introduction. Once I realised I could load symbols, VICE was a huge help (I had previously been manually printing out addresses at compile time in KickAssembler).
But as I went back to refactor and optimise routines I found myself getting pretty frustrated at subtle bugs creeping in which became difficult to track down. Thankfully there is a nice unit test solution for the C64. Yes, unit testing on the C64. Michael Taszycki of the excellent 64Bites video series has created the 64spec framework, which allows you to setup unit tests and run them on the 64 (or in an emulator). This now allows me to make changes and have some confidence that if I break anything I'll be able to catch it early.
And so now things are at the point where balls/bubbles/whatever fall down, stack up and get removed when chains of 3+ matching items are found. Next on my plate is some more refactoring and optimisation, then I need to tackle using sprites for the moving items so they look a little less crap.