Fool’s Mate Friday: One Player or Two?

It was interesting to me that white did not always move first in chess. Apparently, in 1857, a master of chess, Mr. Lowenthal made a recommendation to the First American Chess Congress that white should always move first as a rule. However, that rule was not actually enforced until sometime in the 1900’s. Supposedly, they used to toss coins to see who went first, and that player could choose either color.

red

It might also be noteworthy that the pieces were not always black or white, as some old sets used red as one of the colors. Obviously, today you can get a chess set in any style or color imaginable.

In either event, JustChess is now one or two player! You can choose to play as black or white. Currently, the game is pretty rough around the edges, with a few notable bugs. You can check out the commit at my GitHub.

At present, the JustChessEngine is not very bright, to say the least. But currently, there are issues with the moves sometimes making an erroneous change to the board. Two player mode works as expected, however, en passant still needs to be fixed.

Perhaps when I iron out those bugs, I can release a 0.1 version.

Linux – keep it simple.

Fool’s Mate Friday: Pawn Promotion Possibilities!

Back in the middle ages, there were several different renditions of pawn promotion. Originally, the pawn would promote to the queen piece, but back then the queen could only move one space, like the king. Then there was the rule that the pawn could promote only to a captured piece. So if there were no captured pieces, the pawn would sit there on the end row until one was captured, which would immediately replace the pawn.

Perhaps the most interesting rule, though, was that of the pawn being promoted to the piece on which it’s rank was. E.g, the queen’s bishop’s pawn (c2) would promote to a bishop, a knights pawn a knight, and a king or queens pawn, to that of a queen. This would definitely change the face of a chess match as we know it!

The two player functionality of my chess app, in pass and play mode, is getting closer and closer to completion! Today I had a few minutes and I still had several obstacles to fix, so I decided to tackle one of them.

if (myMove.contains("P48")||myMove.contains("P49")||myMove.contains("P50")||
        myMove.contains("P51")||myMove.contains("P52")||myMove.contains("P53")||
        myMove.contains("P54")||myMove.contains("P55")) {
    if ( minusNum == 8) {
        myMove = "Pu" + promoteToW + played + String.valueOf(theBoard[number]);
    } else if (minusNum == 9) {
        myMove = "Pr" + promoteToW + played + String.valueOf(theBoard[number]);
    } else if (minusNum == 7) {
        myMove = "Pl" + promoteToW + played + String.valueOf(theBoard[number]);
    }
}

if (myMove.contains("p08")||myMove.contains("p09")||myMove.contains("p10")||
        myMove.contains("p11")||myMove.contains("p12")||myMove.contains("p13")||
        myMove.contains("p14")||myMove.contains("p15")) {
    if ( plusNum == 8) {
        myMove = "pu" + getPromoteToB + played + String.valueOf(theBoard[number]);
    } else if (plusNum == 7) {
        myMove = "pr" + getPromoteToB + played + String.valueOf(theBoard[number]);
    } else if (plusNum == 9) {
        myMove = "pl" + getPromoteToB + played + String.valueOf(theBoard[number]);
    }
}

pawn_promote

Essentially, I just added a check to see if it was a pawn promotion when you choose what you are trying to do. Fortunately, there is only one row for black, and one row for white where this maneuver can be done. Be sure to check out the commit for the comparison of the changes.

Linux – keep it simple.

Fool’s Mate Friday: Castle, anyone?

From the git-go, one of the hardest parts of making this chess engine and the following gui system has always been the pawns and the king. Both of these pieces have unusual maneuvers that you can’t easily explain with the traditional shorthand that I was using for the engine. Things like castling, en passant, and promotions.

If you recall last time, I made the pieces movable with a simple two touch interface. The problem is, it checks against the engine to see if that is a legitimate move in the form of piece+square from+square to+captured. This works great for queens and bishops, rooks or knights, but doesn’t bode well when someone tries to castle. This brought me to a fork in the road: change my engine, or manipulate my gui.

I think I should have changed my engine, but I already re-wrote it from scratch, twice. I just don’t have the time to do that again. So, I went with the easier/quicker/less skilled method of manipulating the gui.

Here’s the commit:

public void moveablePiece (View view) {

    // Get the clicked squares tag to see what number it is.
    int number = Integer.parseInt(view.getTag().toString());
    String played;
    if (number < 10) {
        played = "0" + String.valueOf(number);
    } else {
        played = String.valueOf(number);
    }

    if (firstClick) {

        firstClick=false;
        String myMove = tryMove + played + String.valueOf(theBoard[number]);
        Log.i("WJH", myMove);

        if (myMove.equalsIgnoreCase("K0406*")){myMove="K-0-0R";}
        else if (myMove.equalsIgnoreCase("K0402*")){myMove="K0-0-0";}
        else if (myMove.equalsIgnoreCase("k6062*")){myMove="k-0-0r";}
        else if (myMove.equalsIgnoreCase("k6058*")){myMove="k0-0-0";}
        Log.i("WJH", myMove);
        moveOptions= terminal("availMoves,"+String.valueOf(wTurn));

        String[] separated = moveOptions.split(",");

        if (Arrays.asList(separated).contains(myMove)) {

            String query = terminal("myMove,"+myMove);
            Log.i("WJH", query);
            drawBoardPieces();
            wTurn = !wTurn;

        }
        tryMove = "";
        myMove = "";
        mCtv.setText(moveOptions);

    } else {

        firstClick=true;
        tryMove = String.valueOf(theBoard[number]) + played;
        Log.i("WJH", tryMove);
        String query = terminal("pieceMoves,"+ String.valueOf(theBoard[number]) +
                "," + played);
        mCtv.setText(query);
    }

} // End clicked piece.

Essentially, I know there are only 4 possible ways for a king to castle, so I make the gui check to see if that is the case, and then pass the correct move verbiage to the engine. Pretty slick trick for the moment, but it may fall short for en passant. I’ll have to check on that…

Linux – keep it simple.

Fool’s Mate Friday: Now with moving pieces!

According to the Guinness World Records, the biggest playable chess set was made in Canada in 2009, with a king that was about 4 feet tall! Try moving that chunk of wood! Fortunately for me, moving these “wooden” chess pieces doesn’t require much by way of heavy lifting!

twoplayer

It isn’t exactly a walk in the park, either though. Making this game two player and movable was actually pretty simple:

public void moveablePiece (View view) {

    // Get the clicked squares tag to see what number it is.
    int number = Integer.parseInt(view.getTag().toString());
    String played;
    if (number < 10) {
        played = "0" + String.valueOf(number);
    } else {
        played = String.valueOf(number);
    }

    if (firstClick) {

        firstClick=false;
        String myMove = tryMove + played + String.valueOf(theBoard[number]);
        Log.i("WJH", myMove);
        moveOptions= terminal("availMoves,"+String.valueOf(wTurn));

        String[] separated = moveOptions.split(",");

        if (Arrays.asList(separated).contains(myMove)) {

            String query = terminal("myMove,"+myMove);
            Log.i("WJH", query);
            drawBoardPieces();
            wTurn = !wTurn;

        }
        tryMove = "";
        myMove = "";
        mCtv.setText(moveOptions);

    } else {

        firstClick=true;
        tryMove = String.valueOf(theBoard[number]) + played;
        Log.i("WJH", tryMove);
        String query = terminal("pieceMoves,"+ String.valueOf(theBoard[number]) +
                "," + played);
        mCtv.setText(query);
    }

} // End clicked piece.

But the problem that I have now is that the method I use to move the pieces doesn’t work well with the engine when it comes to castling, promoting, or en passant. So I may need to adjust the JustChessEngine to be more of a FEN style input/output. We’ll have to see.

Linux – keep it simple.

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.

Fool’s Mate Friday: JustChess, shaken, not stirred….

Well, I suppose the Bond reference does sound a bit out of place here, but perhaps if we break it down it will not seem to be so.

In the 1963 movie “From Russia With Love” James Bond is facing a fierce and brilliant opponent, Russian agent Kronsteen, who during the opening scene takes down the Canadian Grandmaster McAdams in a chess tournament. The point being is that Bond is not up against an imbecile, but rather a strategic genius.

Of course, Bond’s favorite drink was was a dry martini with a slice of lemon, “shaken, not stirred.” I’m not a drinking man myself, but I have come to understand that shaking the mixture actually does make a difference over stirring, according to Wikipedia. My point in using this phrase is that to make my JustChessEngine playable, I am not just going to stir it in, but shake it up a bit, as I add it to my new app: JustChess. I know, that is a very original name!

 

The first thing on the agenda was to move the launch point of the app to be an “intro” screen, where the player could choose between single player (against the JustChessEngine) or two player, one against the other. At this point, I’m planning to focus on the first, that of playing against the engine.

Be sure to stop by my GitHub and check it out:  https://github.com/alaskalinuxuser/app_JustChess

Linux – keep it simple.