Sunday, February 19, 2012

Tracking playing pieces


To date we've come up with a capacitive detecting circuit which tells us when
a) a piece is introduced (put down) on the playing board
b) when a piece is either lifted off the board, or released

It's part B that's causing us a headache for use as an intelligent board game.
The two actions are actually opposite of each other, so it's difficult to track where exactly on the board a piece is at any one time.

For example, in our test-rig, when an LED lights up, we know that
a) a piece is above a capacitive sensing pad
b) the player has hold of the piece (this is necessary to provide the "ground" for the capacitive part of the sensor

So when an LED lights up, we know that a piece is in the square above the sensor. The problem comes when understanding what has happened when the LED goes out:

Either the player has put the piece down in the square and let go of it OR the player has lifted the piece off the board and continues to hold it in their hand. These are opposite statements - when an LED goes out, either the piece is on the board, or it's been lifted off. Hmmmmm. How to tackle this one?


Let's say we start the game with a completely empty board (and a matrix/array of empty cells).
The controller (whatever that will end up being, either a character LCD or a PC connected to the board or something similar) tells the player to put down a specific piece on the board - for the sake of example, we'll use chess pieces, but the principle applies to lots of other board games.

We could keep a track of the "last piece touched" or "piece in hand".
In this case, the controller sets which piece is in hand (by telling the player to pick up, for example, a black knight). Now when an input is activated (LED lights up) the board can record the playing piece type in the matrix/array. So if pad 1 lights up, it can say "square one contains a black knight".

If, sometime after this, pad 2 lights up, the board would say "the piece in hand is a black knight. Find which square contains the black knight. Square one is now empty, the black knight is now in square two." By doing this, every time a square "lights up" we simply clear the previous location and update the playing piece to the new location. This works well for a single playing piece on the board.

When we introduce more than one playing piece (which, let's be honest would make for a pretty board board game if we couldn't) things get a little more complicated, but the same principles <i>should</i> still work:

When a square lights up:
  • Check to see what playing piece is in this square
  • If no playing piece is in this square, we're working with the previously held piece - clear the previous square and update this one to say the last held playing piece is now in a new location.
  • If a playing piece is found, remember this is now the held playing piece and wait for a different square to light up.
This should allow us to deal with a player simply touching and releasing a piece (the LED lights up and goes out, the board knows that the square already has a piece in it and simply updates which piece is "in hand"). When the player lifts a piece off the board, the LED lights up then goes out and the board updates which piece is in hand (since it knows that the detected square contains a playing piece). But now, when the piece is put back down in a different square, a different LED lights up, the board knows that this square is empty, so updates the location of the piece "in hand".

By using this method, it should be possible to keep track of any number of playing pieces on the game board.

The only problem we can see so far is when removing pieces from the board completely. For example, when a white queen takes a black pawn:

The player picks up the white queen to start moving. The player picks up the black pawn and removes it completely from the board. The player puts the white queen in the black pawn's old square. If more than one piece is moved during a turn, things could get messy!

In this example, the board detects the white queen being lifted off the board (white queen is "in hand"), then it "sees" the black pawn being lifted off the board (black pawn is in hand) then a piece (the board doesn't know which) appears on the black pawn's square. It's possible that the board thinks the black pawn is the piece in hand, and so says that the black pawn is back in the black pawn's square - leaving the white queen where it was.

The solution to this, is to have an "offboard area":
The board sees the black pawn is in hand (when the player lifts it off the board). The black pawn is removed from the board and put into an offboard area. The board now updates the black pawn's old square and makes it free. The player then picks up the white queen (the board puts the white queen "in hand") and places it in the black pawn's old square. The board recognises that this square is now empty, so updates the location of the white queen in the matrix/game array.


No comments:

Post a Comment