Example #1
0
        private void checkUpLeft(Square currentSquare, Player cPlayer)
        {
            int i = currentSquare.getX();
            int j = currentSquare.getY();

            while (i >= 2 && j >= 2)
            {
                Square sq = squares[i - 1, j - 1];
                if (currentSquare.getY() - sq.getY() >= 2 && currentSquare.getX() - sq.getX() >= 2 &&
                    sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor())
                {
                    if (LRDiagonalCheck(sq, currentSquare))
                    {
                        Moves.Add(new Move(cPlayer, currentSquare));
                    }

                    break;
                }
                else if (currentSquare.getY() - sq.getY() <= 1 && currentSquare.getX() - sq.getX() <= 1 &&
                         sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor())
                {
                    break;
                }
                i -= 1; j -= 1;
            }
        }
Example #2
0
        private void checkDownRight(Square currentSquare, Player cPlayer)
        {
            int i = currentSquare.getX();
            int j = currentSquare.getY();

            while (j <= 7 && i <= 7)
            {
                Square sq = squares[i + 1, j + 1];
                if (sq.getY() - currentSquare.getY() >= 2 && sq.getX() - currentSquare.getX() >= 2 &&
                    sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor())
                {
                    if (LRDiagonalCheck(currentSquare, sq))
                    {
                        Moves.Add(new Move(cPlayer, currentSquare));
                    }

                    break;
                }
                else if (currentSquare.getY() - sq.getY() <= 1 && currentSquare.getX() - sq.getX() <= 1 &&
                         sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor())
                {
                    break;
                }
                i += 1; j += 1;
            }
        }
Example #3
0
        private void checkUp(Square currentSquare, Player cPlayer)
        {
            int i = currentSquare.getX();
            int j = currentSquare.getY();

            while (j >= 2)
            {
                //Console.WriteLine(i + " " + j);
                Square sq = squares[i, j - 1];
                if (currentSquare.getY() - sq.getY() >= 2 &&
                    sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor())
                {
                    //Console.WriteLine("Same square found " + sq.getX() + " " + sq.getY());

                    if (CheckVerticalBetween(sq, currentSquare))
                    {
                        Moves.Add(new Move(cPlayer, currentSquare));
                    }

                    break;
                }
                else if (currentSquare.getY() - sq.getY() <= 1 &&
                         sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor())
                {
                    break;
                }
                j -= 1;
            }
        }
Example #4
0
        private bool RLDiagonalCheck(Square s1, Square s2)
        {
            bool addition = false;

            int i = s1.getX();
            int j = s1.getY();

            if (s1.getX() - s2.getX() == 2 && s2.getY() - s1.getY() == 2)
            {
                if (squares[i - 1, j + 1].isOccupied() && s1.isOccupied() &&
                    squares[i - 1, j + 1].getPiece().getColor() != s1.getPiece().getColor())
                {
                    addition = true;
                }
            }
            else
            {
                Square required = squares[i - 1, j + 1];

                while (i > s2.getX() && j < s2.getY())
                {
                    if (squares[i, j].isOccupied() && required.isOccupied() &&
                        squares[i, j].getPiece().getColor() == required.getPiece().getColor())
                    {
                        addition = true;
                    }
                    else
                    {
                        addition = false;
                    }
                    i -= 1; j += 1;
                }
            }
            return(addition);
        }
Example #5
0
        private void ChangeDown(int x, int y)
        {
            int i = x; int j = y + 1;

            while (j <= 7)
            {
                Square sq = gameBoard.squares[i, j];
                if (sq.isOccupied() && Math.Abs(sq.getY() - y) == 1)
                {
                    if (sq.getPiece().getColor() == currPlayer.getPlayerColor())
                    {
                        break;
                    }
                    else
                    {
                        j++;
                    } continue;
                }
                else
                {
                    if (sq.isOccupied() && sq.getPiece().getColor() == currPlayer.getPlayerColor())
                    {
                        changeBetween(i, j, x, y);
                        break;
                    }
                    else
                    {
                        j++;
                    } continue;
                }
            }
        }
Example #6
0
        private void ChangeUpLeft(int x, int y)
        {
            int i = x - 1; int j = y - 1;

            while (j >= 1 && i >= 1)
            {
                Square sq = gameBoard.squares[i, j];
                if (sq.isOccupied() && Math.Abs(sq.getY() - y) == 1 && Math.Abs(sq.getX() - x) == 1)
                {
                    if (sq.getPiece().getColor() == currPlayer.getPlayerColor())
                    {
                        break;
                    }
                    else
                    {
                        i--;
                    } j--; continue;
                }
                else
                {
                    if (sq.isOccupied() && sq.getPiece().getColor() == currPlayer.getPlayerColor())
                    {
                        changeBetween(i, j, x, y);
                        break;
                    }
                    else
                    {
                        i--;
                    } j--; continue;
                }
            }
        }
Example #7
0
        private void checkRight(Square currentSquare, Player cPlayer)
        {
            int i = currentSquare.getX();
            int j = currentSquare.getY();

            while (i <= 7)
            {
                //Console.WriteLine(i + " " + j);
                Square sq = squares[i + 1, j];
                if (sq.getX() - currentSquare.getX() >= 2 &&
                    sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor())
                {
                    //Console.WriteLine("Same square found " + sq.getX() + " " + sq.getY());
                    Console.WriteLine("About to Check between " + currentSquare.getX() + " " + sq.getX());
                    if (checkHorizontalBetween(currentSquare, sq))
                    {
                        Moves.Add(new Move(cPlayer, currentSquare));
                    }

                    break;
                }
                else if (currentSquare.getX() - sq.getX() <= 1 &&
                         sq.isOccupied() && sq.getPiece().getColor() == cPlayer.getPlayerColor())
                {
                    break;
                }
                i += 1;
            }
        }
Example #8
0
        private bool CheckVerticalBetween(Square s1, Square s2)
        {
            bool addition = false;

            int i = s1.getX();

            if (s2.getY() - s1.getY() == 2)
            {
                //Console.WriteLine("Checking " + (s1.getX() + 1) + " " + j);
                //Console.WriteLine(s1.getPiece().getColor().ToString());
                if (squares[i, s1.getY() + 1].isOccupied() && s1.isOccupied() &&
                    squares[i, s1.getY() + 1].getPiece().getColor() != s1.getPiece().getColor())
                {
                    //Console.WriteLine("Square Found");
                    addition = true;
                }
            }
            else
            {
                Square required = squares[i, s1.getY() + 1];
                Console.WriteLine("Checking from " + (s1.getY() + 1) + " to " + (s2.getY() - 1));
                for (int j = s1.getY() + 1; j < s2.getY(); j++)
                {
                    if (squares[i, j].isOccupied() && required.isOccupied() &&
                        squares[i, j].getPiece().getColor() == required.getPiece().getColor())
                    {
                        //Console.WriteLine("Same squares are " + i + " " + (i + 1));
                        addition = true;
                    }
                    else
                    {
                        addition = false;
                    }
                }

                /*                if (addition)
                 *                  Console.WriteLine("From " + (s1.getX()+1) + " to " + (s2.getX()-1) + " Are the Same");*/
            }
            return(addition);
        }
Example #9
0
 public String toString()
 {
     return("[" + movingSquare.getX() + ", " + movingSquare.getY() + "]");
 }