## Sunday, April 17, 2011

### Converting Human Piece Moves to Chess Program Input

Here I have done some more planning so that it will be straightforward when writing the code for detecting human chess piece moves.
We will have an 8 by 8 matrix that stores the current state of the board. Recall the RTI will find a 0 logical input if there is a piece, and 1 logical input if there is no piece. For example when the game first starts out the program will obtain the following board state matrix:
{  {0, 0, 0, 0, 0, 0, 0, 0}
{0, 0, 0, 0, 0, 0, 0, 0}
{1, 1, 1, 1, 1, 1, 1, 1}
{1, 1, 1, 1, 1, 1, 1, 1}
{1, 1, 1, 1, 1, 1, 1, 1}
{1, 1, 1, 1, 1, 1, 1, 1}
{1, 1, 1, 1, 1, 1, 1, 1}
{1, 1, 1, 1, 1, 1, 1, 1}  }

Note that the state matrix won’t look exactly like the chessboard. It will look like a flipped mirrored image because the matrix starts at (0,0) at the top left, whereas the chessboard starts at (A,1). This is ok, because the program just needs to extract the start coordinates and end coordinates of the piece the human moves. It will be a direct map from the board to this matrix.

For example, say we move a pawn from C2 to C3 on the physical chessboard. The RTI system sees this as moving from (1,2) to (2,2). Note that chess labeling is not (row, column) like matrix notation, it’s (column, row). The program will catch the change from 0 to 1 in the board state matrix at coordinate (1,2), (we will incorporate some debouncing here). The program will have a four character long string and change the first two characters to “C2  “. Then the program will catch the change from 1 to 0 in the board state matrix at coordinate (2,2), (again some debouncing). The character string will then be updated to “C2C3”. This move of “C2C3” will then be passed into the computer program. The computer will then output it’s move.

The following is the correspondence table. The row number (of the board state matrix) corresponds to the second coordinate, whereas the column number corresponds to a letter which is the first coordinate:

We still need to work out the exact details as to what will happen if a person makes an illegal move. We were thinking a red LED will be lit until the piece is moved back to where it started, and then the person could move again.