Smart Game Board – Software and testing

Software

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.

 

IDE

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
http://www.visualmicro.com/

 

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! 🙂 ).

Smart Game Board – Manual

International Checkers – Game Rules

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!

Questions? Feedback?
Thoughts on the project?

Leave a comment and I’ll get back to you 🙂

9 thoughts on “Smart Game Board – Software and testing

  1. Pingback:Smart Game Board – Electronics – Bogdan Berg

  2. Is the code available to look at anywhere? I want to try a version of this that can track a game of chess an output a log in algebraic notation.

    1. Hi Raymond, I’m not sure if my source will be a lot of help in your scenario (I’m not keeping a track of each move, to output the history or allow backtracking), but I’m going to send the sources to your e-mail. Hope you’ll find something helpful/interesting! 🙂

    1. Hey Aken!
      I e-mailed you the sources (I need to put some time aside and maybe put them on github, but there’s always a new and shiny project to work on instead! 🙂 ).

      1. Hey there Bogdan!
        Super neat project! Was wondering if the code is available? I would like to try and build this for myself 🙂

        1. Hi Eric, I e-mailed you the sources. Hope you’ll find them useful! Let me know if you have any questions, and if you build a similar project, please share a photo with me 🙂

  3. Hey!
    I am trying to make similar project.. Can you please guide how should I start and from where should I start.
    Plus I would request you to help me with software part too..
    Is code is available online ?

    Thank you!

    1. Hi Zain,

      I like to work on projects like that by dissecting them into smaller pieces. In fact, such decomposition is common in software development as well. Makes things… manageable 😉

      You can think of it as making a progress in clearly defined, iterative steps. For example, I first focused on making a single row of LEDs being controllable and reading the state of pieces on the game board. This allows for easier debugging if something goes wrong, and ensures everything works as expected early on, without the risk that we’ll get ourselves deep into a solution that may prove limiting later on.

      Check out some of my videos on YT from initial testing: https://www.youtube.com/watch?v=Ts9eacRvi6A and https://www.youtube.com/watch?v=tQgYRBa68rw.

      Regarding the software – I e-mailed you the source. Hope you’ll find it educational! Let me know if you have any questions.

Leave a Reply

Your email address will not be published. Required fields are marked *