Fool’s Mate Friday: Identifying the board square by number.

Identification please! Did you know that there have been numerous cases of mistaken identity for the masters of chess in print? There are so many that websites have even devoted entire pages to these mix ups! You can check out some good ones here, where among others, Bernhard Kagan was confused for Alexander Alekhine!

A case of mistaken identity is a bit of a problem. A problem I hope to avoid in my JustChess app. Particularly, I am referring to the pieces that you click on. My next goal of the app is to make it possible to have a human player challenge the JustChess Engine. To do so, I need the player to be able to move the pieces.

clickedjustchess

In retrospect, there may be better ways to do this, but for now, I have tagged all 64 squares of the board, and made them “clickable”. When clicked, the board now returns the tag number. This tag number can simply be cross referenced with the virtual board’s character array to find the corresponding piece. Here’s a break down of the code:

public void moveablePiece (View view) {

    // Get the clicked squares tag to see what number it is.
    int played = Integer.parseInt(view.getTag().toString());

    Log.i("WJH", "clicked sqaure "+ String.valueOf(played));
    Log.i("WJH", "clicked piece "+ theBoard[played]);
    moveOptions= terminal("availMoves,"+String.valueOf(wTurn));
    mCtv.setText(moveOptions);

} // End clicked piece.

What?! Pretty simple isn’t it. All that transpires is the clicked square (which is a view) calls this function and returns it’s own tag. The tag equates to the square number and that number is cross referenced with the board.

Now that the piece is properly identified, I can cross reference it with available moves, highlight those squares, and make it an option to move there, or not move at all. Easy right? Let’s hope so!

Linux – keep it simple.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s