Having everything assembled and tested (all the connections), I started with writing libraries for the LEDs, sensors and handling overall game board state. Then came the game logic (Checkers). Nothing really surprising, and if you’re feeling comfortable with C++ this should be a fairly straight forward step.
I wanted to organize code efficiently, so I can continue adding support for new games (or replace existing with new ones, if the Arduino’s memory size proves to be an issue).
I ended up simplifying pieces of code before finishing the game: originally I thought of a way to handle animations without blocking the input (single-threaded platform), but then I reached conclusion that it seems a bit like an overkill – animations are fast and short lasting, and any change in game board is handled with no more than maybe 1 second delay in the worst case.
One thing to call out: since we’re using magnets and hall effect sensors, the game pieces are indistinguishable between one another – we either get a low or high signal from sensor on any given cell. Thus the complete game logic is based on knowledge of initial state, and then tracking the state changes as players make their moves.
Arduino IDE is very lightweight and convenient for quick development of smaller programs. However, once you start working on anything more complex, and you’d like to be able to design your code more appropriately, it starts to feel very limited. I use, and highly recommend, the Visual Micro – Arduino IDE for Microsoft Visual Studio:
Arduino IDE for Microsoft Visual Studio
High level look at the project
Here’s how I organized my project files:
That should give an idea on what are the main classes, their responsibilities, and how is the game logic organized.
Manual and game rules (International Checkers)
I wanted to make it easier for anyone to have fun with the game board, so I prepared a short manual.
Also, in the process of testing it with my friends and colleagues, I discovered that the US Checkers rules are slightly different than International Checkers. Those subtleties should be explained to players before hand to avoid surprises (and being suspected of cheating! 🙂 ).
Grid – the game board is larger than printer paper (letter format), thus I needed to print 2 copies, cut them and put under the top acrylic panel. This grid has every other cell filled with a pattern to give the classic feel of light and dark cells of a Chess board. The debug version has addresses of the cells for quick reference while writing/debugging the code.
Smart Game Board – Grid + Smart Game Board – Debug Grid
Ideas and improvements for V2
Having the complete project in from of me, and played a number of games (some won, some lost…), here are some of the things I’d like to improve for next version:
- Thicker base, for added sturdiness (3/8″ instead of 1/8″?)
- Revisit dimensions for holes for tabs as they’re a bit loose (looks like I added an offset for both width and height, while it’s only needed in one dimension as the other one is constant, not affected by laser kerf)
- All made from acrylic, including the inner grid (use white acrylic instead of wood) – nicer looks, less susceptible to bending compared to wood drying over time
- Use a “multiplexed” grid for reading the sensor states
- Big improvement in number of I/O ports required (instead of 64, we could use 16: 8 for power, 8 for input), would clean up the overall look, decrease cost and complexity, allow for enclosing this side of the board with nice frame
- This is an approach that is used i.e. in computer keyboards
- Potentially use custom LED strip, instead of being limited by the pitch of available strips – but this adds a significant amount of work, and I didn’t feel limited by the pitch of LEDs on the strip I used
- Instead of support beams around the electronics, use solid walls, with cutouts for ventilation
- This would be sturdier, and prevent players from i.e. dropping the game pieces inside the electronics box
- Print and cut the board face (with white and black cells) using some kind of white transparent foil, instead of printer paper, for a more finished look
- Include place for the switches and buttons in the design – right now they look like an afterthought (which they actually were… 🙂 )
- Maybe add a “tray” where users could store pieces removed from the board (in addition to existing boxes with lids, for when players know they will be playing another game and putting pieces in/out of the box is a hassle – my friends and I keep the pieces on top of the boxes between games)
And going even further:
- Add a LCD screen (display current player, info/warning/error message [i.e. “must jump”, “incorrect move”, “pieces missing from the board”]
- Add a chess timer – used by chess players to measure the time they needed to make a move, for more competitive players
Now let’s start playing!
Thoughts on the project?
Leave a comment and I’ll get back to you 🙂