Tags

, , , , , , , , , , ,

Huo chess 0.961

Introduction

Coding is easy.

Today there are a lot of people learning how to do it.

Why not you?

And you know what is the most difficult step in learning how to code?

TO START LEARNING.

For this ultra quick training I will use a Java edition of my Huo Chess program. This edition lacks basic functionalities like deep searching, but it can however play chess according to the rules and choose the best move at the current position based on which move earns the most material.

License: You can reuse the code you see here in any way you want, as long as you mention the author and the place where you read it first!

Step 1: Get a programming interface

This tutorial will show you how to code a demo chess program in one day, even without any prior knowledge of programming. All you need is a programming interface to write and compile (i.e. make an executable program out of your code) the code that you will write. These are also known as Programming IDEs (Integrated Development Interfaces). This could be the Microsoft Visual Studio (the Express edition of which can be downloaded for free) for C# or any Java compiling studio available out there (like NetBeans for example, which again can be downloaded for free).

The tutorial will not cover the details on how to use these programming interfaces. But this is not something hard to learn anyway. Just go to the web (or the page of the tool itself) and you will gain an understanding on how to write a small console program (this is what we are going to do here) in less than an hour. When I refer to a console program I mean a program which does not have graphics but only displays text. We will start with building such a program since writing code for graphics will surely need an additional effort to learn how to do it. And it will be easy to later on add graphics to your program, once you have the AI logic of the chess engine up and ready, don’t you think?

Tools to use for coding your program

  • Microsoft Visual Studio (free edition)
  • Java NetBeans

After you download the IDE, install it in your computer and go to the option New Project. Select to create a simple C# console application (in Visual Studio) or a simple Java program (in NetBeans). Click Create and there you are. You have the shell in which you will add your chess program code!

Step 2: Design the chess program structure

Let’s go into the chess program now.

But wait!

Don’t we need to learn the programming language first?

The answer is simple: NO!

You will learn them as you go.

This is how I (and many others) learned programming in the first place. I opened my Commodore computer and started typing my first program by copying the code from the manual. After I typed it in and spent time to get it right (even copying can be difficult, especially if you are a rookie) I typed RUN and I had my first game! Forget the long chapters of books trying to teach you – after reading 100 pages – how to just print “Hello world” on a screen. Programming is for people who like experimenting and are not afraid to simply start trying things on their machine.

So just go ahead!

You will read here about the basic structure needed for the program, and then you will see the commands required to code that structure into a C# or Java program. The commands are fairly simple and you will understand what they do as you write the program. Do you really need a programming language manual to understand what an “if” command does anyway?

The main structure of the program is depicted in the following schema.

Huo Chess Java main structure v0.1

Fairly simple isn’t it?

The story goes like this…

  1. You get input from the user for his move. [EnterMove function]
  2. You check the legality and the validity of the move entered [ElegxosNomimotitas and ElegxosOrthotitas functions, which also utilize the CheckForWhiteCheck and CheckForBlackCheck functions to check if there is a check in the position]
  3. If the move is legal and valid, then do the move. [call drawPosition function to redraw the chessboard; note that the Java edition of the program only prints the chessboard in text]
    • Exercise for you: Add graphics to the application. (use the C# edition ot get some insight on how you could do that)
  4. Call the function which makes the computer think. [ComputerMove function]
  5. Scan the chessboard to find all the pieces of the computer. In the sample code provided for Java, this means that it scans for all the black pieces since the program is made only for the computer to play with black.
    • Exercise for you: Add the ability for the program to play with white as well)
  6. For each piece of the computer, check all possible moves to all possible squares of the chessboard.
  7. If you find a valid move (by invoking the ElegxosNomimotitas and ElegxosOrthotitas functions) then do the move and count the score of the position. [CountScore function: This is one of the most central functions of the program; changing it makes the computer play differently according to the values you assign to pieces or to elements of the chessboard like empty ranks, concentration of the pieces at the center et cetera]
  8. If the score of the move is better than the so far better score, then store this position as the best one. (Note: The program stores the first position analyzed as ‘best’ anyway, so that there is a starting point for the best score)
    • Exercise for you: Change the values in the CountScore function to improve the playing abilities of the computer)
  9. Do the best move found and redraw the chessboard.
  10. Wait for next user input. [call EnterMove function again]

The Java edition of the program does not think in more depth. It just finds the move which earns the more material and makes it. This is not chess isn’t it? Well actually it is. The basis for a good chess program. All you have to do is improve it.

Look at the C# version of “Huo Chess” (search the web for it, there are many repositories where I have uploaded the code, including MSDN Library, CodePlex and Codeproject) to gain a small insight on how the chess program can search into more depth.

Exercise for you: Make the Java edition of the program to think in more depths, by adding more “ComputerMove”-like functions to analyze the next potential moves for the human and the computer. Be careful how you pass over the chessboard between these functions. (yes, Google will be your best friend)

Related resources for C# Huo Chess edition

Step 3 : Write the code

This last section contains the source code of the chess program in Java.

As mentioned above, look for “C# Huo Chess” in the web (See the Recourse listed above) to see the full source code of that Huo Chess edition. This code is also heavily commented to make it easy to read and re-use, while the names of the functions are the same as in the Java edition of the program.

Look also at the “How to program a chess program for dummies” series here in Harmonia Philosophica, to get some more details on the Huo Chess program. (the tools used in those articles are a bit outdated, but yet the logic is still the same)

<Beginning of the source code>

package huoChess;

import java.util.Scanner;

public class HuoChess {

// Huo Chess by Spiros Kakos (2018)
// License: Reuse the code as you please, as long as you mention the author and where you first read it!

// Declare variables

// Player color
public static String playerColor;
// Who plays
public static String whoPlays;
// Move related variables
public static String playerMove;
public static String movingPiece;
public static String startingColumn;
public static String startingRank;
public static String finishingColumn;
public static String finishingRank;
public static int startingRankNum;
public static int finishingRankNum;
public static int startingColumnNum;
public static int finishingColumnNum;
public static boolean moveValidity;
public static boolean moveLegality;
// Additional variables for check legality of move
public static int p, h;
public static int how_to_move_Rank = 0;
public static int how_to_move_Column = 0;
public static boolean m_WrongColumn;
public static boolean exit_elegxos_nomimothtas;
public static boolean enpassant_occured;
public static String ProsorinoKommati_KingCheck;
public static boolean WhiteKingCheck;
public static boolean BlackKingCheck;
public static int WhiteKingColumn;
public static int WhiteKingRank;
public static int BlKingColumn;
public static int BlKingRank; 
public static boolean DangerFromRight;
public static boolean DangerFromLeft;
public static boolean DangerFromUp;
public static boolean DangerFromDown;
public static boolean DangerFromUpRight;
public static boolean DangerFromDownLeft;
public static boolean DangerFromDownRight;
public static boolean DangerFromUpLeft;
// Variables to store the best move
public static boolean bestMoveFound;
public static int bestStartingColumn;
public static int bestStartingRank;
public static int bestFinishingColumn;
public static int bestFinishingRank;
// Variables to store the score
public static double tempScore;
public static double bestScore;
// The chessboard
public static String[][] chessBoard = new String[8][8];
public static String[][] drawChessBoard = new String[8][8];
// The tool used to read the input from the user
static Scanner reader = new Scanner(System.in);

public static void main(String[] args) {

// Ask for the color the player wants to play with
System.out.println("Huo Chess by Spiros Kakos");
System.out.println("Please choose color (w/b)");
playerColor = reader.next();

// Print the choice of the player
System.out.println("Your choice: " + playerColor);
// Transform w and b to White and Black and print again (not needed, just to show how the if command works)
if (playerColor.equals("w"))
System.out.println("Your color : " + "White");
else if (playerColor.equals("b"))
System.out.println("Your color : " + "Black");
else
System.out.println("Invalid choice");

if (playerColor.equals("w"))
{
// Human player plays
whoPlays = "human";
// Call the function which sets up the initial position
startingPosition();
// Call the function which draws the position
drawPosition();

// Call the function which asks from the user to enter his move
EnterMove();
}

}

// Function which sets up the initial chessboard position
public static void startingPosition() {

// Note that chessboard ranks and columns numbers start from 0
// i = Column (starting from 0)
// j = Rank (starting from 0)

for (int i = 7; i > -1; i--)
{
for (int j = 7; j > -1; j--)
{
// Clear the chessboard
chessBoard[i][j] = "";
}
}

// Put the pieces in the chessboard (e.g. WR for White Rook)
chessBoard[0][0] = "WR";
chessBoard[0][1] = "WP";
chessBoard[1][0] = "WN";
chessBoard[1][1] = "WP";
chessBoard[2][0] = "WB";
chessBoard[2][1] = "WP";
chessBoard[3][0] = "WQ";
chessBoard[3][1] = "WP";
chessBoard[4][0] = "WK";
chessBoard[4][1] = "WP";
chessBoard[5][0] = "WB";
chessBoard[5][1] = "WP";
chessBoard[6][0] = "WN";
chessBoard[6][1] = "WP";
chessBoard[7][0] = "WR";
chessBoard[7][1] = "WP";
// Put the black pieces as well
chessBoard[0][7] = "BR";
chessBoard[0][6] = "BP";
chessBoard[1][7] = "BN";
chessBoard[1][6] = "BP";
chessBoard[2][7] = "BB";
chessBoard[2][6] = "BP";
chessBoard[3][7] = "BQ";
chessBoard[3][6] = "BP";
chessBoard[4][7] = "BK";
chessBoard[4][6] = "BP";
chessBoard[5][7] = "BB";
chessBoard[5][6] = "BP";
chessBoard[6][7] = "BN";
chessBoard[6][6] = "BP";
chessBoard[7][7] = "BR";
chessBoard[7][6] = "BP";
}

// Function to draw the chessboard position
// It simply prints the pieces, nothing fancy
public static void drawPosition() {

// Transform chessboard to the drawChessBoard
// by adding spaces in the empty squares.
// This allows the program to draw a decent chessboard.
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
if (!chessBoard[i][j].equals(""))
drawChessBoard[i][j] = chessBoard[i][j];
else if (chessBoard[i][j].equals(""))
drawChessBoard[i][j] = " ";
}
}
// Print an empty line to separate the printed chessboard from the previous text in the screen
System.out.println("");

// Print one rank at a time
//for (int i = 7; i > -1; i--)
//{
// System.out.println(
// "[" + chessBoard[0][i] + "]" +
// "[" + chessBoard[1][i] + "]" +
// "[" + chessBoard[2][i] + "]" +
// "[" + chessBoard[3][i] + "]" +
// "[" + chessBoard[4][i] + "]" +
// "[" + chessBoard[5][i] + "]" +
// "[" + chessBoard[6][i] + "]" +
// "[" + chessBoard[7][i] + "]" 
// );
//}

System.out.println(
"-------------------------");

// Print one rank at a time
for (int i = 7; i > -1; i--)
{
System.out.println(
"|" + drawChessBoard[0][i] +
"|" + drawChessBoard[1][i] +
"|" + drawChessBoard[2][i] +
"|" + drawChessBoard[3][i] +
"|" + drawChessBoard[4][i] +
"|" + drawChessBoard[5][i] +
"|" + drawChessBoard[6][i] +
"|" + drawChessBoard[7][i] + "|" 
);

System.out.println(
"-------------------------");
}


}

// Function which asks for the user to enter his move 
public static void EnterMove() {
System.out.println("");
System.out.println("Enter move (e.g. c2c4) and press Enter. Enter 'q' to quit.");
// Read the move the user inputs
playerMove = reader.next();

// Break the move entered in starting and finishing columns and ranks
startingColumn = Character.toString( playerMove.charAt(0) );
startingRank = Character.toString( playerMove.charAt(1) );
finishingColumn = Character.toString( playerMove.charAt(2) );
finishingRank = Character.toString( playerMove.charAt(3) );

if(playerMove.equals("q"))
System.exit(0);

System.out.println("Move : " + startingColumn + startingRank + " -> " + finishingColumn + finishingRank);

// Convert characters to numbers for the program to be able to process them
startingRankNum = Integer.valueOf(startingRank);

finishingRankNum = Integer.valueOf(finishingRank);

switch (startingColumn)
{
case "a":
startingColumnNum = 1; break;
case "b":
startingColumnNum = 2; break;
case "c":
startingColumnNum = 3; break;
case "d":
startingColumnNum = 4; break;
case "e":
startingColumnNum = 5; break;
case "f":
startingColumnNum = 6; break;
case "g":
startingColumnNum = 7; break;
case "h":
startingColumnNum = 8; break;
}

switch (finishingColumn)
{
case "a":
finishingColumnNum = 1; break;
case "b":
finishingColumnNum = 2; break;
case "c":
finishingColumnNum = 3; break;
case "d":
finishingColumnNum = 4; break;
case "e":
finishingColumnNum = 5; break;
case "f":
finishingColumnNum = 6; break;
case "g":
finishingColumnNum = 7; break;
case "h":
finishingColumnNum = 8; break;
}

// Store the moving piece in the relative variable
movingPiece = chessBoard[(startingColumnNum-1)][(startingRankNum-1)];
System.out.println("Piece: " + movingPiece);
System.out.println("Move : " + startingColumnNum + startingRankNum + " -> " + finishingColumnNum + finishingRankNum);
//movingPiece = chessBoard[(startingRankNum-1)][(startingColumnNum-1)];

// Just a test to show how if statement is working
// if ((startingRankNum == finishingRankNum) || (startingColumnNum == finishingColumnNum))
// System.out.println("Test 1!");

// Call the function which checks for move legality.
// There result of the check will be returned to the variable moveLegality
// The parameters passed over to the function are the starting and finishing ranks and columns plus the moving piece
whoPlays = "Human";
m_WrongColumn = false;
// Call the function which checks the move's legality
// startingRankNum = startingRankNum + 1;
// startingColumnNum = startingColumnNum + 1;
// finishingRankNum = finishingRankNum + 1;
// finishingColumnNum = finishingColumnNum + 1;
moveValidity = ElegxosOrthotitas(chessBoard, 0, startingRankNum, startingColumnNum, finishingRankNum, finishingColumnNum, movingPiece);
moveLegality = ElegxosNomimotitas(chessBoard, 0, startingRankNum, startingColumnNum, finishingRankNum, finishingColumnNum, movingPiece);

if ((moveValidity == true) && (moveLegality == true))
{
System.out.println("Valid move");
// Do the move
chessBoard[(finishingColumnNum-1)][(finishingRankNum-1)] = movingPiece;
chessBoard[(startingColumnNum-1)][(startingRankNum-1)] = "";
// Draw the chessboard
drawPosition();
// Call the function to start the computer thinking
computerMove(chessBoard);
}
else
{
System.out.println("Wrong move!");
}
}

// Function which makes the computer think of his own move
public static void computerMove(String[][] CMchessboard) {

// i = Column (starting from 0)
// j = Rank (starting from 0)
// Use chessBoard[(startingColumnNum-1)][(startingRankNum-1)] to read
// the chessboard since the table indexes start from zero (0).

// Initialize variables
String MovingPiece = "";
String ProsorinoKommati = "";
int m_StartingColumnNumber = 0;
int m_FinishingColumnNumber = 0;
int m_StartingRank = 0;
int m_FinishingRank = 0;
tempScore = 0;
bestScore = 0;
bestStartingColumn = 0;
bestStartingRank = 0;
bestFinishingColumn = 0;
bestFinishingRank = 0;
bestMoveFound = false;

//System.out.println(CMchessboard[0][6].substring(0,1));

// Scan the chessboard
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
// Scan all possible moves
// (only for the computer''s pieces)
if ( (!CMchessboard[i][j].equals("")) && (CMchessboard[i][j].substring(0,1).equals("B")) )
{
// Store the moving piece
MovingPiece = CMchessboard[i][j];
// Store the initial coordinates
// Remember that the m_StartingColumnNumber, m_StartingRank
// variables have values from 1 to 8 (not from 0 to 7 as the
// chessboard array indexes)
m_StartingColumnNumber = i + 1;
m_StartingRank = j + 1;

// Make all possible moves for that piece
for (int ii= 0; ii < 8; ii++)
{
for (int jj = 0; jj < 8; jj++)
{
// For every possible destination square...
// Store the destination coordinates
// (again add 1 because the i, j, ii, jj variables have values
// 0 to 7 while the moveValidity and moveLegality functions
// need as input the normal starting & finishing columns and
// ranks (i.e. with values from 1 to 8)
m_FinishingColumnNumber = ii + 1;
m_FinishingRank = jj + 1;
// Store the piece at the destination
ProsorinoKommati = CMchessboard[ii][jj];
// And then test the validity of the move
whoPlays = "Human";
m_WrongColumn = false;
// Call the function which checks the move's legality
moveValidity = ElegxosOrthotitas(CMchessboard, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
moveLegality = ElegxosNomimotitas(CMchessboard, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
whoPlays = "HY";

// If move is valid, make it and count the score!
if ((moveValidity == true) && (moveLegality == true))
{
CMchessboard[i][j] = "";
CMchessboard[ii][jj] = MovingPiece;

tempScore = countScore(CMchessboard);

// If no best move has been found yet, store the
// move as the first best move found
if (bestMoveFound == false)
{
bestStartingColumn = m_StartingColumnNumber;
bestStartingRank = m_StartingRank;
bestFinishingColumn = m_FinishingColumnNumber;
bestFinishingRank = m_FinishingRank;
// Now you have a best move found!
bestMoveFound = true;
}
// If the new score is lower than the current best
// (note that we want lower scores since the computer
// plays with black), then store the new best move
if(tempScore < bestScore)
{
bestStartingColumn = m_StartingColumnNumber;
bestStartingRank = m_StartingRank;
bestFinishingColumn = m_FinishingColumnNumber;
bestFinishingRank = m_FinishingRank;
}

// Undo the move
CMchessboard[i][j] = MovingPiece;
CMchessboard[ii][jj] = ProsorinoKommati;
}
}
} 

}

}
}

System.out.println("");
System.out.println("Found best move: " + bestStartingColumn + bestStartingRank
+ " -> " + bestFinishingColumn + bestFinishingRank);

// Do the best move!
MovingPiece = chessBoard[bestStartingColumn-1][bestStartingRank-1];
chessBoard[bestStartingColumn-1][bestStartingRank-1] = "";
chessBoard[bestFinishingColumn-1][bestFinishingRank-1] = MovingPiece;

// Draw the chessboard again
drawPosition();

// Call function to get user input again
EnterMove();
}

// Function to measure the score of a position in the chessboard
public static double countScore(String[][] skakieraCS) {
int score = 0;

// Scan the chessboard
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
// Increase the score for any white piece you find
if (skakieraCS[i][j].equals("WR"))
score = score + 5;
else if (skakieraCS[i][j].equals("WN"))
score = score + 3;
else if (skakieraCS[i][j].equals("WB"))
score = score + 3;
else if (skakieraCS[i][j].equals("WQ"))
score = score + 9;
else if (skakieraCS[i][j].equals("WK"))
score = score + 50;
else if (skakieraCS[i][j].equals("WP"))
score = score + 1; 
// Derease the score for any black piece you find
else if (skakieraCS[i][j].equals("BR"))
score = score - 5;
else if (skakieraCS[i][j].equals("BN"))
score = score - 3;
else if (skakieraCS[i][j].equals("BB"))
score = score - 3;
else if (skakieraCS[i][j].equals("BQ"))
score = score - 9;
if (skakieraCS[i][j].equals("BK"))
score = score - 50;
else if (skakieraCS[i][j].equals("BP"))
score = score - 1;
}
}

return score;
}

public static boolean ElegxosNomimotitas(String[][] ENSkakiera, int checkForDanger, int startRank, int startColumn, int finishRank, int finishColumn, String MovingPiece_2) 
{ 
// TODO: Add your control notification handler code here

boolean Nomimotita;
//Console.WriteLine("into Elegxos Nomimotitas");

////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος της "ΝΟΜΙΜΟΤΗΤΑΣ" της κίνησης. Αν π.χ. ο χρήστης έχει επιλέξει να κινήσει έναν πύργο από
// το α2 στο α5, αλλά στο α4 υπάρχει κάποιο πιόνι του, τότε η Nomimotita έχει τιμή false.
// Η συνάρτηση "επιστρέφει" τη booleanean μεταβλητή Nomimotita.
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////

Nomimotita = true;

if( ((finishRank-1) > 7) || ((finishRank-1) < 0) || ((finishColumn-1) > 7) || ((finishColumn-1) < 0) )
Nomimotita = false;

// if a piece of the same colout is in the destination square...
if (checkForDanger == 0)
{
if ((MovingPiece_2.equals("WK")) || (MovingPiece_2.equals("WQ")) || (MovingPiece_2.equals("WR")) || (MovingPiece_2.equals("WN")) || (MovingPiece_2.equals("WB")) || (MovingPiece_2.equals("WP")))
{
if ((ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("WK")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("WQ")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("WR")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("WN")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("WB")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("WP")))
{
Nomimotita = false;
}
}
else if ((MovingPiece_2.equals("BK")) || (MovingPiece_2.equals("BQ")) || (MovingPiece_2.equals("BR")) || (MovingPiece_2.equals("BN")) || (MovingPiece_2.equals("BB")) || (MovingPiece_2.equals("BP")))
{
if ((ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("BK")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("BQ")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("BR")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("BN")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("BB")) || (ENSkakiera[((finishColumn - 1))][((finishRank - 1))].equals("BP")))
Nomimotita = false;
}
}

if (MovingPiece_2.equals("WK"))
{
if (checkForDanger == 0)
{
/////////////////////////
// WK
/////////////////////////
// is the king threatened in the destination square?
// temporarily move king
ENSkakiera[(startColumn - 1)][(startRank - 1)] = "";
ProsorinoKommati_KingCheck = ENSkakiera[(finishColumn - 1)][(finishRank - 1)];
ENSkakiera[(finishColumn - 1)][(finishRank - 1)] = "WK";

WhiteKingCheck = CheckForWhiteCheck(ENSkakiera);

if (WhiteKingCheck == true)
Nomimotita = false;

// restore pieces
ENSkakiera[(startColumn - 1)][(startRank - 1)] = "WK";
ENSkakiera[(finishColumn - 1)][(finishRank - 1)] = ProsorinoKommati_KingCheck;
}
}
else if (MovingPiece_2.equals("BK"))
{
if (checkForDanger == 0)
{
///////////////////////////
// BK
///////////////////////////
// is the BK threatened in the destination square?
// temporarily move king
ENSkakiera[(startColumn - 1)][(startRank - 1)] = "";
ProsorinoKommati_KingCheck = ENSkakiera[(finishColumn - 1)][(finishRank - 1)];
ENSkakiera[(finishColumn - 1)][(finishRank - 1)] = "BK";

BlackKingCheck = CheckForBlackCheck(ENSkakiera);

if (BlackKingCheck == true)
{
Nomimotita = false;
}

// restore pieces
ENSkakiera[(startColumn - 1)][(startRank - 1)] = "BK";
ENSkakiera[(finishColumn - 1)][(finishRank - 1)] = ProsorinoKommati_KingCheck;
}
}
else if (MovingPiece_2.equals("WP"))
{
if (checkForDanger == 0)
{
//Console.WriteLine("checking WP");
System.out.println("Checkpoint 2");

/////////////////////
// WP
/////////////////////

// move forward

if ((finishRank == (startRank + 1)) && (finishColumn == startColumn))
{
if (!ENSkakiera[(finishColumn - 1)][(finishRank - 1)].equals(""))
{
//Console.WriteLine("pawn Nomimotita false");
Nomimotita = false;

System.out.println("Checkpoint 2.1 - Wrong move");
}
}

// move forward for 2 squares
else if ((finishRank == (startRank + 2)) && (finishColumn == startColumn))
{
if (startRank == 2)
{
if ((!ENSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("")) || (!ENSkakiera[(finishColumn - 1)][(finishRank - 1 - 1)].equals("")))
{
Nomimotita = false;
System.out.println("Checkpoint 2.2 - Wrong move");
System.out.println("Checkpoint 2.2 - Final square : " + ENSkakiera[(finishColumn - 1)][(finishRank - 1)]);
System.out.println("Checkpoint 2.2 - Pre-final square : " + ENSkakiera[(finishColumn - 1)][(finishRank - 1 - 1)]);
}
}
}

// eat forward to the right

else if ((finishRank == (startRank + 1)) && (finishColumn == startColumn + 1))
{
if (enpassant_occured == false)
{
if (ENSkakiera[(finishColumn - 1)][(finishRank - 1)].equals(""))
{
Nomimotita = false;
System.out.println("Checkpoint 2.3 - Wrong move");
}
}
}

// eat forward to the left

else if ((finishRank == (startRank + 1)) && (finishColumn == startColumn - 1))
{
if (enpassant_occured == false)
{
if (ENSkakiera[(finishColumn - 1)][(finishRank - 1)].equals(""))
{
Nomimotita = false;
System.out.println("Checkpoint 2.4 - Wrong move");
}
}
}
}
}
else if (MovingPiece_2.equals("BP"))
{
if (checkForDanger == 0)
{
/////////////////////
// BP
/////////////////////

// move forward

if ((finishRank == (startRank - 1)) && (finishColumn == startColumn))
{
if (!ENSkakiera[(finishColumn - 1)][(finishRank - 1)].equals(""))
Nomimotita = false;
}

// move forward for 2 squares
else if ((finishRank == (startRank - 2)) && (finishColumn == startColumn))
{
if (startRank == 7)
{
if ((!ENSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("")) || (!ENSkakiera[(finishColumn - 1)][(finishRank + 1 - 1)].equals("")))
Nomimotita = false;
}
}

// eat forward to the right

else if ((finishRank == (startRank - 1)) && (finishColumn == startColumn + 1))
{
if (enpassant_occured == false)
{
if (ENSkakiera[(finishColumn - 1)][(finishRank - 1)].equals(""))
Nomimotita = false;
}
}

// eat forward to the left

else if ((finishRank == (startRank - 1)) && (finishColumn == startColumn - 1))
{
if (enpassant_occured == false)
{
if (ENSkakiera[(finishColumn - 1)][(finishRank - 1)].equals(""))
Nomimotita = false;
}
}
}
}
else if( (MovingPiece_2.equals("WR")) || (MovingPiece_2.equals("WQ")) || (MovingPiece_2.equals("WB")) || (MovingPiece_2.equals("BR")) || (MovingPiece_2.equals("BQ")) || (MovingPiece_2.equals("BB")) )
{
h = 0;
p = 0;
//hhh = 0;
how_to_move_Rank = 0;
how_to_move_Column = 0;

if(((finishRank-1) > (startRank-1)) || ((finishRank-1) < (startRank-1)))
how_to_move_Rank = ((finishRank-1) - (startRank-1))/ Math.abs((finishRank-1) - (startRank-1));

if(((finishColumn-1) > (startColumn-1)) || ((finishColumn-1) < (startColumn-1)) )
how_to_move_Column = ((finishColumn-1) - (startColumn-1))/Math.abs((finishColumn-1) - (startColumn-1));

exit_elegxos_nomimothtas = false;

do
{
h = h + how_to_move_Rank;
p = p + how_to_move_Column;

if( (((startRank-1) + h) == (finishRank-1)) && ((((startColumn-1) + p)) == (finishColumn-1)) )
exit_elegxos_nomimothtas = true;

if((startColumn - 1 + p)<0)
exit_elegxos_nomimothtas = true;
else if((startRank - 1 + h)<0)
exit_elegxos_nomimothtas = true;
else if((startColumn - 1 + p)>7)
exit_elegxos_nomimothtas = true;
else if((startRank - 1 + h)>7)
exit_elegxos_nomimothtas = true;

// if a piece exists between the initial and the destination square,
// then the move is illegal!
if( exit_elegxos_nomimothtas == false )
{
if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("WR"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("WN"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("WB"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("WQ"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("WK"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("WP"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}

if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("BR"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("BN"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("BB"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("BQ"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("BK"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
else if(ENSkakiera[(startColumn - 1 + p)][(startRank - 1 + h)].equals("BP"))
{
Nomimotita = false;
exit_elegxos_nomimothtas = true;
}
}
}while(exit_elegxos_nomimothtas == false);
}
return Nomimotita;
}

// FUNCTION TO CHECK THE CORRECTNESS (='Orthotita' in Greek) OF THE MOVE
// (i.e. a Bishop can only move in diagonals, rooks in lines and columns etc)
// The ElegxosOrthotitas "checkForDanger" mode differs from the ElegxosOrthotitas normal mode in that it does not make all the validations
// (since it is used to check for "Dangerous" squares in the chessboard and not to actually judge the correctness of an actual move)
public static boolean ElegxosOrthotitas(String[][] EOSkakiera, int checkForDanger, int startRank, int startColumn, int finishRank, int finishColumn, String MovingPiece_2)
{
// TODO: Add your control notification handler code here

// If called for checking dangerous squares, put a virtual piece in the destination square so as to pass the validation checks
// if (checkForDanger == 1)
// Don't care about checking for the existence of a piece in the destination square


boolean Orthotita;
Orthotita = false;
enpassant_occured = false;

//Console.WriteLine("ElegxosOrthotitas");
//Console.WriteLine(MovingPiece_2);

//Micro edition 2: Convert small Strings to Int
//If m_WhoPlays = Human
if ((whoPlays.equals("Human")) && (m_WrongColumn == false) && (!MovingPiece_2.equals(""))) // Αν ο χρήστης έχει γράψει μία έγκυρη στήλη και έχει
{ // επιλέξει να κινήσει ένα κομμάτι (και δεν έχει επι-
// λέξει να κινήσει ένα "κενό" τετράγωνο) και είναι η σειρά του να παίξει, τότε να γί-
// νει έλεγχος της ορθότητας της κίνησης.

//Console.WriteLine("1");

// ROOK

if ((MovingPiece_2.equals("WR")) || (MovingPiece_2.equals("BR")))
{
if ((finishColumn != startColumn) && (finishRank == startRank)) // Κίνηση σε στήλη
Orthotita = true;
else if ((finishRank != startRank) && (finishColumn == startColumn)) // Κίνηση σε γραμμή
Orthotita = true;
}

// horse (with knight...)

if ((MovingPiece_2.equals("WN")) || (MovingPiece_2.equals("BN")))
{
if ((finishColumn == (startColumn + 1)) && (finishRank == (startRank + 2)))
Orthotita = true;
else if ((finishColumn == (startColumn + 2)) && (finishRank == (startRank - 1)))
Orthotita = true;
else if ((finishColumn == (startColumn + 1)) && (finishRank == (startRank - 2)))
Orthotita = true;
else if ((finishColumn == (startColumn - 1)) && (finishRank == (startRank - 2)))
Orthotita = true;
else if ((finishColumn == (startColumn - 2)) && (finishRank == (startRank - 1)))
Orthotita = true;
else if ((finishColumn == (startColumn - 2)) && (finishRank == (startRank + 1)))
Orthotita = true;
else if ((finishColumn == (startColumn - 1)) && (finishRank == (startRank + 2)))
Orthotita = true;
else if ((finishColumn == (startColumn + 2)) && (finishRank == (startRank + 1)))
Orthotita = true;
}

// bishop

if ((MovingPiece_2.equals("WB")) || (MovingPiece_2.equals("BB")))
{
////////////////////
// 2009 v4 change
////////////////////
//if ((Math.abs(finishColumn - startColumn)) == (Math.abs(finishRank - startRank)))
// Orthotita = true;
if (((Math.abs(finishColumn - startColumn)) == (Math.abs(finishRank - startRank))) && (finishColumn != startColumn) && (finishRank != startRank))
Orthotita = true;
////////////////////
// 2009 v4 change
////////////////////
}

// queen

if ((MovingPiece_2.equals("WQ")) || (MovingPiece_2.equals("BQ")))
{
if ((finishColumn != startColumn) && (finishRank == startRank)) // Κίνηση σε στήλη
Orthotita = true;
else if ((finishRank != startRank) && (finishColumn == startColumn)) // Κίνηση σε γραμμή
Orthotita = true;

////////////////////
// 2009 v4 change
////////////////////
// move in diagonals
//if ((Math.abs(finishColumn - startColumn)) == (Math.abs(finishRank - startRank)))
// Orthotita = true;
if (((Math.abs(finishColumn - startColumn)) == (Math.abs(finishRank - startRank))) && (finishColumn != startColumn) && (finishRank != startRank))
Orthotita = true;
////////////////////
// 2009 v4 change
////////////////////
}

// king

if ((MovingPiece_2.equals("WK")) || (MovingPiece_2.equals("BK")))
{
// move in rows and columns

if ((finishColumn == (startColumn + 1)) && (finishRank == startRank))
Orthotita = true;
else if ((finishColumn == (startColumn - 1)) && (finishRank == startRank))
Orthotita = true;
else if ((finishRank == (startRank + 1)) && (finishColumn == startColumn))
Orthotita = true;
else if ((finishRank == (startRank - 1)) && (finishColumn == startColumn))
Orthotita = true;

// move in diagonals

else if ((finishColumn == (startColumn + 1)) && (finishRank == (startRank + 1)))
Orthotita = true;
else if ((finishColumn == (startColumn + 1)) && (finishRank == (startRank - 1)))
Orthotita = true;
else if ((finishColumn == (startColumn - 1)) && (finishRank == (startRank - 1)))
Orthotita = true;
else if ((finishColumn == (startColumn - 1)) && (finishRank == (startRank + 1)))
Orthotita = true;

}

// WP

if (MovingPiece_2.equals("WP"))
{
// move forward
//Console.WriteLine("2");
System.out.println("Checkpoint 1");
System.out.println("startRank =" + startRank);
System.out.println("finishRank =" + finishRank);
System.out.println("startColumn =" + startColumn);
System.out.println("finishColumn =" + finishColumn);

if ((finishRank == (startRank + 1)) && (finishColumn == startColumn))
{
Orthotita = true;
System.out.println("Checkpoint 1.1 - Valid move");
}

// move forward for 2 squares
else if ((finishRank == (startRank + 2)) && (finishColumn == startColumn) && (startRank == 2))
{
Orthotita = true;
System.out.println("Checkpoint 1.2 - Valid move");
}

else if ((finishRank == (startRank + 1)) && ((finishColumn == (startColumn - 1)) || (finishColumn == (startColumn + 1))))
{
if (checkForDanger == 0)
{
// eat forward to the left
if ((finishRank == (startRank + 1)) && (finishColumn == (startColumn - 1)) && ((EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BP")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BR")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BN")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BB")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BQ"))))
Orthotita = true;

// eat forward to the right
if ((finishRank == (startRank + 1)) && (finishColumn == (startColumn + 1)) && ((EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BP")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BR")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BN")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BB")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("BQ"))))
Orthotita = true;
}
else if (checkForDanger == 1)
{
Orthotita = true;
}
}

// En Passant eat forward to the left
else if ((finishRank == (startRank + 1)) && (finishColumn == (startColumn - 1)))
{
if (checkForDanger == 0)
{
//Console.WriteLine(finishRank.ToString());
//Console.WriteLine(finishColumn.ToString());
//Console.WriteLine("checking En passant...");
if ((finishRank == 6) && (EOSkakiera[(finishColumn - 1)][(4)].equals("BP")))
{
Orthotita = true;
enpassant_occured = true;
EOSkakiera[(finishColumn - 1)][(finishRank - 1 - 1)] = "";
//Console.WriteLine("En passant true");
}
else
{
Orthotita = false;
enpassant_occured = false;
}
}
}

// En Passant eat forward to the right
else if ((finishRank == (startRank + 1)) && (finishColumn == (startColumn + 1)))
{
if (checkForDanger == 0)
{
if ((finishRank == 6) && (EOSkakiera[(finishColumn - 1)][(4)].equals("BP")))
{
Orthotita = true;
enpassant_occured = true;
EOSkakiera[(finishColumn - 1)][(finishRank - 1 - 1)] = "";
}
else
{
Orthotita = false;
enpassant_occured = false;
}
}
}

}


// BP

if (MovingPiece_2.equals("BP"))
{
// move forward

if ((finishRank == (startRank - 1)) && (finishColumn == startColumn))
Orthotita = true;

// move forward for 2 squares
else if ((finishRank == (startRank - 2)) && (finishColumn == startColumn) && (startRank == 7))
Orthotita = true;

else if ((finishRank == (startRank - 1)) && ((finishColumn == (startColumn + 1)) || (finishColumn == (startColumn - 1))))
{
if (checkForDanger == 0)
{
// eat forward to the left
if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn + 1)) && ((EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WP")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WR")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WN")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WB")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WQ"))))
Orthotita = true;

// eat forward to the right
if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn - 1)) && ((EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WP")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WR")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WN")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WB")) || (EOSkakiera[(finishColumn - 1)][(finishRank - 1)].equals("WQ"))))
Orthotita = true;
}
else if (checkForDanger == 1)
{
// eat forward to the left
if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn + 1)))
Orthotita = true;

// eat forward to the right
if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn - 1)))
Orthotita = true;
}
}

// En Passant eat forward to the left
else if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn + 1)))
{
if (checkForDanger == 0)
{
if ((finishRank == 3) && (EOSkakiera[(finishColumn - 1)][(3)].equals("WP")))
{
Orthotita = true;
enpassant_occured = true;
EOSkakiera[(finishColumn - 1)][(finishRank + 1 - 1)] = "";
}
else
{
Orthotita = false;
enpassant_occured = false;
}
}
}

// En Passant eat forward to the right
else if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn - 1)))
{
if (checkForDanger == 0)
{
if ((finishRank == 3) && (EOSkakiera[(finishColumn - 1)][(3)].equals("WP")))
{
Orthotita = true;
enpassant_occured = true;
EOSkakiera[(finishColumn - 1)][(finishRank + 1 - 1)] = "";
}
else
{
Orthotita = false;
enpassant_occured = false;
}
}
}

}

}

//Console.WriteLine(Orthotita.ToString());
return Orthotita;
}

public static boolean CheckForWhiteCheck(String[][] WCSkakiera) {
boolean KingCheck = false;

int klopa;
int i, j;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Εύρεση των συντεταγμένων του βασιλιά.
// Αν σε κάποιο τετράγωνο βρεθεί ότι υπάρχει ένας βασιλιάς, τότε απλά καταγράφεται η τιμή του εν λόγω
// τετραγώνου στις αντίστοιχες μεταβλητές που δηλώνουν τη στήλη και τη γραμμή στην οποία υπάρχει λευκός
// βασιλιάς.
// ΠΡΟΣΟΧΗ: Γράφω (i+1) αντί για i και (j+1) αντί για j γιατί το πρώτο στοιχείο του πίνακα WCWCSkakiera[(8),(8)]
// είναι το WCSkakiera[(0),(0)] και ΟΧΙ το WCSkakiera[(1),(1)]!
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

for (i = 0; i <= 7; i++)
{
for (j = 0; j <= 7; j++)
{

if (WCSkakiera[(i)][(j)].equals("WK"))
{
WhiteKingColumn = (i + 1);
WhiteKingRank = (j + 1);
}

}
}

///////////////////////////////////////////////////////////////
// Έλεγχος του αν ο λευκός βασιλιάς υφίσταται "σαχ"
///////////////////////////////////////////////////////////////

KingCheck = false;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Ελέγχουμε αρχικά αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΤΑ ΔΕΞΙΑ ΤΟΥ. Για να μην βγούμε έξω από τα
// όρια της WCSkakiera[(8),(8)] έχουμε προσθέσει τον έλεγχο (WhiteKingColumn + 1) <= 8 στο "if". Αρχικά ο "κίνδυνος"
// από τα "δεξιά" είναι υπαρκτός, άρα DangerFromRight = true. Ωστόσο αν βρεθεί ότι στα δεξιά του λευκού βασι-
// λιά υπάρχει κάποιο λευκό κομμάτι, τότε δεν είναι δυνατόν ο εν λόγω βασιλιάς να υφίσταται σαχ από τα δεξιά
// του (αφού θα "προστατεύεται" από το κομμάτι ιδίου χρώματος), οπότε η DangerFromRight = false και ο έλεγχος
// για απειλές από τα δεξιά σταματάει (για αυτό και έχω προσθέσει την προϋπόθεση (DangerFromRight == true) στα
// "if" που κάνουν αυτόν τον έλεγχο).
// Αν όμως δεν υπάρχει κανένα λευκό κομμάτι δεξιά του βασιλιά για να τον προστατεύει, τότε συνεχίζει να
// υπάρχει πιθανότητα να απειλείται ο βασιλιάς από τα δεξιά του, οπότε ο έλεγχος συνεχίζεται.
// Σημείωση: Ο έλεγχος γίνεται για πιθανό σαχ από πύργο ή βασίλισσα αντίθετου χρώματος.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromRight = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((WhiteKingColumn + klopa) <= 8) && (DangerFromRight == true))
{
if ((WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("Black Rook")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("Black Queen")))
KingCheck = true;
else if ((WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("White Pawn")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("White Rook")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("White Knight")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("White Bishop")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("White Queen")))
DangerFromRight = false;
else if ((WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("Black Pawn")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("Black Knight")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("Black Bishop")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - 1)].equals("Black King")))
DangerFromRight = false;
}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΤΑ ΑΡΙΣΤΕΡΑ ΤΟΥ (από πύργο ή βασίλισσα).
///////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromLeft = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((WhiteKingColumn - klopa) >= 1) && (DangerFromLeft == true))
{
if ((WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("Black Rook")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("Black Queen")))
KingCheck = true;
else if ((WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("White Pawn")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("White Rook")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("White Knight")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("White Bishop")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("White Queen")))
DangerFromLeft = false;
else if ((WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("Black Pawn")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("Black Knight")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("Black Bishop")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - 1)].equals("Black King")))
DangerFromLeft = false;
}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΠΑΝΩ (από πύργο ή βασίλισσα).
///////////////////////////////////////////////////////////////////////////////////////////////////////


DangerFromUp = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((WhiteKingRank + klopa) <= 8) && (DangerFromUp == true))
{
if ((WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("Black Rook")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("Black Queen")))
KingCheck = true;
else if ((WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("White Pawn")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("White Rook")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("White Knight")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("White Bishop")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("White Queen")))
DangerFromUp = false;
else if ((WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("Black Pawn")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("Black Knight")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("Black Bishop")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank + klopa - 1)].equals("Black King")))
DangerFromUp = false;
}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΚΑΤΩ (από πύργο ή βασίλισσα).
///////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromDown = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((WhiteKingRank - klopa) >= 1) && (DangerFromDown == true))
{
if ((WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("Black Rook")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("Black Queen")))
KingCheck = true;
else if ((WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("White Pawn")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("White Rook")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("White Knight")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("White Bishop")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("White Queen")))
DangerFromDown = false;
else if ((WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("Black Pawn")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("Black Knight")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("Black Bishop")) || (WCSkakiera[(WhiteKingColumn - 1)][(WhiteKingRank - klopa - 1)].equals("Black King")))
DangerFromDown = false;
}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΠΑΝΩ-ΔΕΞΙΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromUpRight = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((WhiteKingColumn + klopa) <= 8) && ((WhiteKingRank + klopa) <= 8) && (DangerFromUpRight == true))
{
if ((WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Bishop")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Queen")))
KingCheck = true;
else if ((WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Pawn")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Rook")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Knight")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Bishop")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Queen")))
DangerFromUpRight = false;
else if ((WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Pawn")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Rook")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Knight")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black King")))
DangerFromUpRight = false;
}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΚΑΤΩ-ΑΡΙΣΤΕΡΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromDownLeft = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((WhiteKingColumn - klopa) >= 1) && ((WhiteKingRank - klopa) >= 1) && (DangerFromDownLeft == true))
{
if ((WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Bishop")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Queen")))
KingCheck = true;
else if ((WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Pawn")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Rook")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Knight")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Bishop")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Queen")))
DangerFromDownLeft = false;
else if ((WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Pawn")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Rook")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Knight")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black King")))
DangerFromDownLeft = false;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΚΑΤΩ-ΔΕΞΙΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromDownRight = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((WhiteKingColumn + klopa) <= 8) && ((WhiteKingRank - klopa) >= 1) && (DangerFromDownRight == true))
{
if ((WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Bishop")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Queen")))
KingCheck = true;
else if ((WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Pawn")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Rook")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Knight")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Bishop")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("White Queen")))
DangerFromDownRight = false;
else if ((WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Pawn")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Rook")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black Knight")) || (WCSkakiera[(WhiteKingColumn + klopa - 1)][(WhiteKingRank - klopa - 1)].equals("Black King")))
DangerFromDownRight = false;
}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΠΑΝΩ-ΑΡΙΣΤΕΡΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromUpLeft = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((WhiteKingColumn - klopa) >= 1) && ((WhiteKingRank + klopa) <= 8) && (DangerFromUpLeft == true))
{
if ((WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Bishop")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Queen")))
KingCheck = true;
else if ((WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Pawn")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Rook")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Knight")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Bishop")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("White Queen")))
DangerFromUpLeft = false;
else if ((WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Pawn")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Rook")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black Knight")) || (WCSkakiera[(WhiteKingColumn - klopa - 1)][(WhiteKingRank + klopa - 1)].equals("Black King")))
DangerFromUpLeft = false;
}
}

//////////////////////////////////////////////////////////////////////////
// Έλεγχος για το αν ο λευκός βασιλιάς απειλείται από πιόνι.
//////////////////////////////////////////////////////////////////////////

if (((WhiteKingColumn + 1) <= 8) && ((WhiteKingRank + 1) <= 8))
{
if (WCSkakiera[(WhiteKingColumn + 1 - 1)][(WhiteKingRank + 1 - 1)].equals("Black Pawn"))
{
KingCheck = true;
}
}


if (((WhiteKingColumn - 1) >= 1) && ((WhiteKingRank + 1) <= 8))
{
if (WCSkakiera[(WhiteKingColumn - 1 - 1)][(WhiteKingRank + 1 - 1)].equals("Black Pawn"))
{
KingCheck = true;
}
}


///////////////////////////////////////////////////////////////////////
// Έλεγχος για το αν ο λευκός βασιλιάς απειλείται από ίππο.
///////////////////////////////////////////////////////////////////////

if (((WhiteKingColumn + 1) <= 8) && ((WhiteKingRank + 2) <= 8))
if (WCSkakiera[(WhiteKingColumn + 1 - 1)][(WhiteKingRank + 2 - 1)].equals("Black Knight"))
KingCheck = true;

if (((WhiteKingColumn + 2) <= 8) && ((WhiteKingRank - 1) >= 1))
if (WCSkakiera[(WhiteKingColumn + 2 - 1)][(WhiteKingRank - 1 - 1)].equals("Black Knight"))
KingCheck = true;

if (((WhiteKingColumn + 1) <= 8) && ((WhiteKingRank - 2) >= 1))
if (WCSkakiera[(WhiteKingColumn + 1 - 1)][(WhiteKingRank - 2 - 1)].equals("Black Knight"))
KingCheck = true;

if (((WhiteKingColumn - 1) >= 1) && ((WhiteKingRank - 2) >= 1))
if (WCSkakiera[(WhiteKingColumn - 1 - 1)][(WhiteKingRank - 2 - 1)].equals("Black Knight"))
KingCheck = true;

if (((WhiteKingColumn - 2) >= 1) && ((WhiteKingRank - 1) >= 1))
if (WCSkakiera[(WhiteKingColumn - 2 - 1)][(WhiteKingRank - 1 - 1)].equals("Black Knight"))
KingCheck = true;

if (((WhiteKingColumn - 2) >= 1) && ((WhiteKingRank + 1) <= 8))
if (WCSkakiera[(WhiteKingColumn - 2 - 1)][(WhiteKingRank + 1 - 1)].equals("Black Knight"))
KingCheck = true;

if (((WhiteKingColumn - 1) >= 1) && ((WhiteKingRank + 2) <= 8))
if (WCSkakiera[(WhiteKingColumn - 1 - 1)][(WhiteKingRank + 2 - 1)].equals("Black Knight"))
KingCheck = true;

if (((WhiteKingColumn + 2) <= 8) && ((WhiteKingRank + 1) <= 8))
if (WCSkakiera[(WhiteKingColumn + 2 - 1)][(WhiteKingRank + 1 - 1)].equals("Black Knight"))
KingCheck = true;

return KingCheck;
}

public static boolean CheckForBlackCheck(String[][] BCSkakiera) {
boolean KingCheck = false;

int klopa;
int ik, jk;

//System.out.println("");
//System.out.println("Entered CheckForBlackCheck");

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Εύρεση των συντεταγμένων του βασιλιά.
// Αν σε κάποιο τετράγωνο βρεθεί ότι υπάρχει ένας βασιλιάς, τότε απλά καταγράφεται η τιμή του εν λόγω
// τετραγώνου στις αντίστοιχες μεταβλητές που δηλώνουν τη στήλη και τη γραμμή στην οποία υπάρχει μαύρος
// βασιλιάς.
// ΠΡΟΣΟΧΗ: Γράφω (i+1) αντί για i και (j+1) αντί για j γιατί το πρώτο στοιχείο του πίνακα BCSkakiera[(8),(8)]
// είναι το BCSkakiera[(0),(0)] και ΟΧΙ το BCSkakiera[(1),(1)]!
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

for (ik = 0; ik <= 7; ik++)
{
for (jk = 0; jk <= 7; jk++)
{

if (BCSkakiera[(ik)][(jk)].equals("BK"))
{
BlKingColumn = (ik + 1);
BlKingRank = (jk + 1);
//System.out.println("Found king at " + (ik + 1) + (jk + 1));
}

}
}

///////////////////////////////////////////////////////////////
// Έλεγχος του αν ο μαύρος βασιλιάς υφίσταται "σαχ"
///////////////////////////////////////////////////////////////

KingCheck = false;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Ελέγχουμε αρχικά αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΤΑ ΔΕΞΙΑ ΤΟΥ. Για να μην βγούμε έξω από τα
// όρια της BCSkakiera[(8),(8)] έχουμε προσθέσει τον έλεγχο (BlKingColumn + 1) <= 8 στο "if". Αρχικά ο "κίνδυνος"
// από τα "δεξιά" είναι υπαρκτός, άρα DangerFromRight = true. Ωστόσο αν βρεθεί ότι στα δεξιά του μαύρου βασι-
// λιά υπάρχει κάποιο μαύρο κομμάτι, τότε δεν είναι δυνατόν ο εν λόγω βασιλιάς να υφίσταται σαχ από τα δεξιά
// του (αφού θα "προστατεύεται" από το κομμάτι ιδίου χρώματος), οπότε η DangerFromRight = false και ο έλεγχος
// για απειλές από τα δεξιά σταματάει (για αυτό και έχω προσθέσει την προϋπόθεση (DangerFromRight == true) στα
// "if" που κάνουν αυτόν τον έλεγχο).
// Αν όμως δεν υπάρχει κανένα μαύρο κομμάτι δεξιά του βασιλιά για να τον προστατεύει, τότε συνεχίζει να
// υπάρχει πιθανότητα να απειλείται ο βασιλιάς από τα δεξιά του, οπότε ο έλεγχος συνεχίζεται.
// Σημείωση: Ο έλεγχος γίνεται για πιθανό σαχ από πύργο ή βασίλισσα αντίθετου χρώματος.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromRight = true;

//System.out.println("BlKingColumn = " + BlKingColumn);
//System.out.println("BlKingRank = " + BlKingRank);

for (klopa = 1; klopa <= 7; klopa++)
{
if (((BlKingColumn + klopa) <= 8) && (DangerFromRight == true))
{
if ((BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("White Rook")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("White Queen")))
KingCheck = true;
else if ((BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("Black Pawn")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("Black Rook")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("Black Knight")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("Black Bishop")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("Black Queen")))
DangerFromRight = false;
else if ((BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("White Pawn")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("White Knight")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("White Bishop")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - 1)].equals("White King")))
DangerFromRight = false;
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΤΑ ΑΡΙΣΤΕΡΑ ΤΟΥ (από πύργο ή βασίλισσα).
///////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromLeft = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((BlKingColumn - klopa) >= 1) && (DangerFromLeft == true))
{
if ((BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("White Rook")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("White Queen")))
KingCheck = true;
else if ((BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("Black Pawn")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("Black Rook")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("Black Knight")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("Black Bishop")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("Black Queen")))
DangerFromLeft = false;
else if ((BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("White Pawn")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("White Knight")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("White Bishop")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - 1)].equals("White King")))
DangerFromLeft = false;
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΠΑΝΩ (από πύργο ή βασίλισσα).
///////////////////////////////////////////////////////////////////////////////////////////////////////


DangerFromUp = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((BlKingRank + klopa) <= 8) && (DangerFromUp == true))
{
if ((BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("White Rook")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("White Queen")))
KingCheck = true;
else if ((BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("Black Pawn")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("Black Rook")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("Black Knight")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("Black Bishop")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("Black Queen")))
DangerFromUp = false;
else if ((BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("White Pawn")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("White Knight")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("White Bishop")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank + klopa - 1)].equals("White King")))
DangerFromUp = false;
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΚΑΤΩ (από πύργο ή βασίλισσα).
///////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromDown = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((BlKingRank - klopa) >= 1) && (DangerFromDown == true))
{
if ((BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("White Rook")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("White Queen")))
KingCheck = true;
else if ((BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("Black Pawn")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("Black Rook")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("Black Knight")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("Black Bishop")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("Black Queen")))
DangerFromDown = false;
else if ((BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("White Pawn")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("White Knight")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("White Bishop")) || (BCSkakiera[(BlKingColumn - 1)][(BlKingRank - klopa - 1)].equals("White King")))
DangerFromDown = false;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΠΑΝΩ-ΔΕΞΙΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromUpRight = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((BlKingColumn + klopa) <= 8) && ((BlKingRank + klopa) <= 8) && (DangerFromUpRight == true))
{
if ((BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("White Bishop")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("White Queen")))
KingCheck = true;
else if ((BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Pawn")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Rook")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Knight")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Bishop")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Queen")))
DangerFromUpRight = false;
else if ((BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("White Pawn")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("White Rook")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("White Knight")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank + klopa - 1)].equals("White King")))
DangerFromUpRight = false;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΚΑΤΩ-ΑΡΙΣΤΕΡΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromDownLeft = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((BlKingColumn - klopa) >= 1) && ((BlKingRank - klopa) >= 1) && (DangerFromDownLeft == true))
{
if ((BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("White Bishop")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("White Queen")))
KingCheck = true;
else if ((BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Pawn")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Rook")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Knight")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Bishop")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Queen")))
DangerFromDownLeft = false;
else if ((BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("White Pawn")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("White Rook")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("White Knight")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank - klopa - 1)].equals("White King")))
DangerFromDownLeft = false;
}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΚΑΤΩ-ΔΕΞΙΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromDownRight = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((BlKingColumn + klopa) <= 8) && ((BlKingRank - klopa) >= 1) && (DangerFromDownRight == true))
{
if ((BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("White Bishop")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("White Queen")))
KingCheck = true;
else if ((BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Pawn")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Rook")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Knight")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Bishop")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("Black Queen")))
DangerFromDownRight = false;
else if ((BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("White Pawn")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("White Rook")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("White Knight")) || (BCSkakiera[(BlKingColumn + klopa - 1)][(BlKingRank - klopa - 1)].equals("White King")))
DangerFromDownRight = false;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΠΑΝΩ-ΑΡΙΣΤΕΡΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DangerFromUpLeft = true;

for (klopa = 1; klopa <= 7; klopa++)
{
if (((BlKingColumn - klopa) >= 1) && ((BlKingRank + klopa) <= 8) && (DangerFromUpLeft == true))
{
if ((BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("White Bishop")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("White Queen")))
KingCheck = true;
else if ((BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Pawn")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Rook")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Knight")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Bishop")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("Black Queen")))
DangerFromUpLeft = false;
else if ((BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("White Pawn")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("White Rook")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("White Knight")) || (BCSkakiera[(BlKingColumn - klopa - 1)][(BlKingRank + klopa - 1)].equals("White King")))
DangerFromUpLeft = false;
}
}


//////////////////////////////////////////////////////////////////////////
// Έλεγχος για το αν ο μαύρος βασιλιάς απειλείται από πιόνι.
//////////////////////////////////////////////////////////////////////////

if (((BlKingColumn + 1) <= 8) && ((BlKingRank - 1) >= 1))
{
if (BCSkakiera[(BlKingColumn + 1 - 1)][(BlKingRank - 1 - 1)].equals("White Pawn"))
{
KingCheck = true;
}
}


if (((BlKingColumn - 1) >= 1) && ((BlKingRank - 1) >= 1))
{
if (BCSkakiera[(BlKingColumn - 1 - 1)][(BlKingRank - 1 - 1)].equals("White Pawn"))
{
KingCheck = true;
}
}


///////////////////////////////////////////////////////////////////////
// Έλεγχος για το αν ο μαύρος βασιλιάς απειλείται από ίππο.
///////////////////////////////////////////////////////////////////////

if (((BlKingColumn + 1) <= 8) && ((BlKingRank + 2) <= 8))
if (BCSkakiera[(BlKingColumn + 1 - 1)][(BlKingRank + 2 - 1)].equals("White Knight"))
KingCheck = true;

if (((BlKingColumn + 2) <= 8) && ((BlKingRank - 1) >= 1))
if (BCSkakiera[(BlKingColumn + 2 - 1)][(BlKingRank - 1 - 1)].equals("White Knight"))
KingCheck = true;

if (((BlKingColumn + 1) <= 8) && ((BlKingRank - 2) >= 1))
if (BCSkakiera[(BlKingColumn + 1 - 1)][(BlKingRank - 2 - 1)].equals("White Knight"))
KingCheck = true;

if (((BlKingColumn - 1) >= 1) && ((BlKingRank - 2) >= 1))
if (BCSkakiera[(BlKingColumn - 1 - 1)][(BlKingRank - 2 - 1)].equals("White Knight"))
KingCheck = true;

if (((BlKingColumn - 2) >= 1) && ((BlKingRank - 1) >= 1))
if (BCSkakiera[(BlKingColumn - 2 - 1)][(BlKingRank - 1 - 1)].equals("White Knight"))
KingCheck = true;

if (((BlKingColumn - 2) >= 1) && ((BlKingRank + 1) <= 8))
if (BCSkakiera[(BlKingColumn - 2 - 1)][(BlKingRank + 1 - 1)].equals("White Knight"))
KingCheck = true;

if (((BlKingColumn - 1) >= 1) && ((BlKingRank + 2) <= 8))
if (BCSkakiera[(BlKingColumn - 1 - 1)][(BlKingRank + 2 - 1)].equals("White Knight"))
KingCheck = true;

if (((BlKingColumn + 2) <= 8) && ((BlKingRank + 1) <= 8))
if (BCSkakiera[(BlKingColumn + 2 - 1)][(BlKingRank + 1 - 1)].equals("White Knight"))
KingCheck = true;

return KingCheck;
}

}

<End of the source code>

READ ALSO:
Reach the clouds.

Paste that code into the main java file in your NetBeans project and compile it.

Execute your program and enjoy your new chess game.

Epilogue

So there it is. Depending on your copy-paste and reading comprehension skills, you now have a working chess program on your hands and some knowledge on how it could be improved. Everything is up to you now.

READ ALSO:
Hitler - Person of the Year (or Do you trust media?)

Happy coding!

And don’t forget: Keep experimenting!

The worst thing that could happen?

To just ruin your computer…

 

Advertisements