Fool’s Mate Friday: Is the King safe from pawns?

Pawns can be scary things. They can en passant, they can form chains and islands, they can promote to the all powerful queen. Not to mention they can checkmate you. That’s right. Even Magnus Carlsen has been checkmated by a pawn (vs. Tal Baron)*. So, if the current world chess champion can get the ax from a pawn, I, being far, far, far (add a few more far-s in there) lesser player, should watch out for them too.

On that note, while testing out my now playable JustChess app, I’ve come to realize a major blunder in the programming! A blunder in regards to my pawns when it comes to king safety! By complete accident, rather than say that a pawn is a threat when forward and diagonal of you, I made pawns life threatening to the king when abreast him!

pawnsafety

Don’t worry, though, I fixed it with this commit. Essentially, I had to change 4 lines, and move the pawn problem from row +/-1 to +/-7 and 9. Now the king can move appropriately when responding to pawns.

// King check // Don't move next to another king! // Also includes pawns.
if (h < 7 ) {
    if (theBoard[z+8]=='k') {
        return false;}
    if (g > 0) {
        if (theBoard[z+7]=='k' || theBoard[z+7]=='p') {
            return false;}}
    if (g < 7) {
        if (theBoard[z+9]=='k' || theBoard[z+9]=='p') {
            return false;}}}
if (h > 0 ) {
    if (theBoard[z-8]=='k') {
        return false;}
    if (g > 0) {
        if (theBoard[z-9]=='k') {
            return false;}}
    if (g < 7) {
        if (theBoard[z-7]=='k') {
            return false;}}}
if (g > 0) {
    if (theBoard[z-1]=='k') {
        return false;}}
if (g < 7) {
    if (theBoard[z+1]=='k') {
        return false;}}
// End white king is safe.

Linux – keep it simple.

* Some imply Tal Baron may have cheated to win this game. This was brought to my attention, so I added the link above for explanation. I’m not sure, I don’t know the man, and have no desire to in any way slight his character. In any event, Mr. Carlsen lost by checkmate to a pawn, either from Mr. Baron or an engine, and most likely Mr. Baron, due to the blitz game being less than 3 minutes. My point in this article still proves true: pawns are dangerous!

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