public override bool canMove(int x1, int y1, int x2, int y2, int Player)
        {
            if (canMoveAux(x1, y1, x2, y2, Player))
            {
                Piece eaten_piece  = BOARD.getPiece(x2, y2);
                Board BOARD_BACKUP = BOARD.backup();
                if (canMoveAux(x1, y1, x2, y2, Player))
                {
                    if ((y1 != y2) && eaten_piece.getClass2() == NullPiece.getClass() && ((ChessPiece)BOARD.getPiece(x1, y1)).get_type().Equals(ChessPiece.PAWN, StringComparison.CurrentCultureIgnoreCase))
                    {
                        eaten_piece = BOARD.getPiece(x1, y2);
                        BOARD.removePiece(x1, y2);
                    }
                    BOARD.movePiece(x1, y1, x2, y2);

                    if (inCheck(Player))
                    {
                        BOARD = BOARD_BACKUP;

                        return(false);
                    }
                    else
                    {
                        BOARD = BOARD_BACKUP;
                        return(true);
                    }
                }
                BOARD = BOARD_BACKUP;
            }
            return(false);
        }
        public bool canAdd(int x, int y, Piece P)
        {
            if ((GAME_ENDED) || (WAITING_PLAYERS))
            {
                return(false);
            }
            if (BOARD.getPiece(x, y).getClass2() != NullPiece.getClass())
            {
                return(false);
            }
            int cont_O = BOARD.contPieces(PLAYER2);
            int cont_X = BOARD.contPieces(PLAYER1);

            if (P.getPlayer() == PLAYER2)
            {
                if (cont_O == cont_X - 1)
                {
                    ACTUAL_PLAYER = PLAYER1;
                    return(true);
                }
            }
            else if ((P.getPlayer() == PLAYER1))
            {
                if (cont_O == cont_X)
                {
                    ACTUAL_PLAYER = PLAYER2;
                    return(true);
                }
            }
            return(false);
        }
 public bool removePiece(int x, int y)
 {
     if (validCell(x, y))
     {
         BOARD[x, y] = new NullPiece();
         return(true);
     }
     return(false);
 }
 public bool movePiece(int x1, int y1, int x2, int y2)
 {
     if (validCell(x1, y1) && validCell(x2, y2))
     {
         BOARD[x2, y2] = BOARD[x1, y1];
         BOARD[x1, y1] = new NullPiece();
         return(true);
     }
     return(false);
 }
 public Board(int x, int y)
 {
     BOARD       = new Piece[x, y];
     DIMENSION_X = x;
     DIMENSION_Y = y;
     for (int contx = 0; contx < x; contx++)
     {
         for (int conty = 0; conty < y; conty++)
         {
             BOARD[contx, conty] = new NullPiece();
         }
     }
 }
 public Position findKing(int Player)
 {
     for (int x = 0; x <= 8; x++)
     {
         for (int y = 0; y <= 8; y++)
         {
             if (BOARD.getPiece(x, y).getClass2() != NullPiece.getClass())
             {
                 if ((((ChessPiece)BOARD.getPiece(x, y)).get_type().Equals(ChessPiece.KING, StringComparison.CurrentCultureIgnoreCase)) && ((ChessPiece)BOARD.getPiece(x, y)).PLAYER == Player)
                 {
                     return(new Position(x, y));
                 }
             }
         }
     }
     return(new Position(-1, -1));
 }
Beispiel #7
0
        private bool cannotMove(int Player)
        {
            if (EAT_MOVE)
            {
                return(false);
            }
            if (GAME_ENDED || WAITING_PLAYERS)
            {
                return(false);
            }
            if (Player != ACTUAL_PLAYER)
            {
                return(false);
            }

            for (int x1 = 0; x1 < 8; x1++)
            {
                for (int y1 = 0; y1 < 8; y1++)
                {
                    if (BOARD.getPiece(x1, y1).getClass2() != NullPiece.getClass())
                    {
                        CheckersPiece P1 = (CheckersPiece)BOARD.getPiece(x1, y1);
                        if (P1.getPlayer() == Player)
                        {
                            for (int dx = 1; dx <= 2; dx++)
                            {
                                for (int posNegX = -1; posNegX < 2; posNegX = posNegX + 2)
                                {
                                    for (int posNegY = -1; posNegY < 2; posNegY = posNegY + 2)
                                    {
                                        int destX = x1 + dx * posNegX;
                                        int destY = x1 + dx * posNegY;
                                        if (BOARD.validCell(destX, destY) && canMove(x1, y1, destX, destY, Player))
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
        public bool thereIsSomeoneInTheWay(int x1, int y1, int x2, int y2)
        {
            int add_x = 1;
            int add_y = 1;

            if (x2 - x1 < 0)
            {
                add_x = -1;
            }
            else if (x2 == x1)
            {
                add_x = 0;
            }
            if (y2 - y1 < 0)
            {
                add_y = -1;
            }
            else if (y2 == y1)
            {
                add_y = 0;
            }
            x1 += add_x;
            y1 += add_y;
            int cont = 0;

            while (x1 != x2 || y1 != y2 && cont < 10)
            {
                cont++;

                if (BOARD.validCell(x1, y1))
                {
                    if ((BOARD.getPiece(x1, y1).getClass2() != NullPiece.getClass()))
                    {
                        return(true);
                    }
                }
                x1 += add_x;
                y1 += add_y;
            }
            return(false);
        }
        public bool canMoveAux(int x1, int y1, int x2, int y2, int Player)
        {
            if (GAME_ENDED || WAITING_PLAYERS)
            {
                return(false);
            }
            if (Player != ACTUAL_PLAYER)
            {
                return(false);
            }

            if (!BOARD.validCell(x1, y1) || !BOARD.validCell(x2, y2))
            {
                return(false);
            }

            if (BOARD.getPiece(x1, y1).getClass2() == NullPiece.getClass())
            {
                return(false);
            }

            bool null_destination = true;

            if (BOARD.getPiece(x2, y2).getClass2() != NullPiece.getClass())
            {
                null_destination = false;
                if (((ChessPiece)BOARD.getPiece(x2, y2)).PLAYER == Player)
                {
                    return(false);
                }
            }



            ChessPiece P1 = (ChessPiece)BOARD.getPiece(x1, y1);

            if (P1.getPlayer() != Player)
            {
                Console.WriteLine("The piece belong to the other player: " + P1.getPlayer() + ", you are " + Player);
                return(false);
            }


            if (P1.get_type().Equals(ChessPiece.PAWN, StringComparison.CurrentCultureIgnoreCase))
            {
                if (Player == PLAYER1)
                {
                    if ((x2 - x1 == -1) && (y2 == y1) && (null_destination))
                    {
                        return(true);
                    }
                    else if ((x2 - x1 == -2) && (y2 == y1) && (x1 == 6) && (null_destination))
                    {
                        return(true);
                    }
                    else if ((x2 - x1 == -1) && Math.Abs(y2 - y1) == 1)
                    {
                        if (!(null_destination))
                        {
                            return(true);
                        }
                        else if (BOARD.getPiece(x1, y2).getClass2() != NullPiece.getClass())
                        {
                            if (((ChessPiece)BOARD.getPiece(x1, y2)).PLAYER != Player && ((ChessPiece)BOARD.getPiece(x1, y2)).get_type().Equals(ChessPiece.PAWN, StringComparison.CurrentCultureIgnoreCase))
                            {
                                if ((LAST_ACTION.getClass2() == MoveAction.getClass()))
                                {
                                    if (((MoveAction)LAST_ACTION).TO_X == x1 && ((MoveAction)LAST_ACTION).TO_Y == y2 && ((ChessPiece)((MoveAction)LAST_ACTION).ACTOR).get_type().Equals(ChessPiece.PAWN, StringComparison.CurrentCultureIgnoreCase) && ((MoveAction)LAST_ACTION).FROM_X == x1 - 2)
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (Player == PLAYER2)
                {
                    if ((x2 - x1 == 1) && (y2 == y1) && (null_destination))
                    {
                        return(true);
                    }
                    else if ((x2 - x1 == 2) && (y2 == y1) && (x1 == 1) && (null_destination))
                    {
                        return(true);
                    }
                    else if ((x2 - x1 == 1) && Math.Abs(y2 - y1) == 1)
                    {
                        if (!(null_destination))
                        {
                            return(true);
                        }
                        else if (BOARD.getPiece(x1, y2).getClass2() != NullPiece.getClass())
                        {
                            if (((ChessPiece)BOARD.getPiece(x1, y2)).PLAYER != Player && ((ChessPiece)BOARD.getPiece(x1, y2)).get_type().Equals(ChessPiece.PAWN, StringComparison.CurrentCultureIgnoreCase))
                            {
                                if ((LAST_ACTION.getClass2() == MoveAction.getClass()))
                                {
                                    if (((MoveAction)LAST_ACTION).TO_X == x1 && ((MoveAction)LAST_ACTION).TO_Y == y2 && ((ChessPiece)((MoveAction)LAST_ACTION).ACTOR).get_type().Equals(ChessPiece.PAWN, StringComparison.CurrentCultureIgnoreCase) && ((MoveAction)LAST_ACTION).FROM_X == x1 + 2)
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (P1.get_type().Equals(ChessPiece.KNIGHT, StringComparison.CurrentCultureIgnoreCase))
            {
                if (((Math.Abs(x2 - x1) == 1) && (Math.Abs(y2 - y1) == 2)) || ((Math.Abs(x2 - x1) == 2) && (Math.Abs(y2 - y1) == 1)))
                {
                    return(true);
                }
            }
            else if (P1.get_type().Equals(ChessPiece.BISHOP, StringComparison.CurrentCultureIgnoreCase))
            {
                if (Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && y2 != y1)
                {
                    if (!thereIsSomeoneInTheWay(x1, y1, x2, y2))
                    {
                        return(true);
                    }
                }
            }
            else if (P1.get_type().Equals(ChessPiece.ROOK, StringComparison.CurrentCultureIgnoreCase))
            {
                if ((x2 - x1 == 0 && Math.Abs(y2 - y1) > 0) || (y2 - y1 == 0 && Math.Abs(x2 - x1) > 0))
                {
                    if (!thereIsSomeoneInTheWay(x1, y1, x2, y2))
                    {
                        return(true);
                    }
                }
            }
            else if (P1.get_type().Equals(ChessPiece.QUEEN, StringComparison.CurrentCultureIgnoreCase))
            {
                if ((x2 - x1 == 0 && Math.Abs(y2 - y1) > 0) || (y2 - y1 == 0 && Math.Abs(x2 - x1) > 0))
                {
                    if (!thereIsSomeoneInTheWay(x1, y1, x2, y2))
                    {
                        return(true);
                    }
                }
                else if (Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && y2 != y1)
                {
                    if (!thereIsSomeoneInTheWay(x1, y1, x2, y2))
                    {
                        return(true);
                    }
                }
            }
            else if (P1.get_type().Equals(ChessPiece.KING, StringComparison.CurrentCultureIgnoreCase))
            {
                if ((Math.Abs(y2 - y1) <= 1) && (Math.Abs(x2 - x1) <= 1) && (Math.Abs(y2 - y1) + Math.Abs(x2 - x1) >= 1))
                {
                    return(true);
                }
                else
                {
                    if (Player == PLAYER1)
                    {
                        if (KING_PLAYER1_MOVED == false)
                        {
                            if (x1 == 7 && y1 == 4 && x2 == 7 && y2 == 6)
                            {
                                if (RIGHT_ROOK_PLAYER1_MOVED == false && BOARD.getPiece(7, 5).getClass2() == NullPiece.getClass() && BOARD.getPiece(7, 6).getClass2() == NullPiece.getClass())
                                {
                                    if (BOARD.getPiece(x1, 7).getClass2().Equals(ChessPiece.getClass()))
                                    {
                                        if (((ChessPiece)BOARD.getPiece(x1, 7)).PLAYER == Player && ((ChessPiece)BOARD.getPiece(x1, 7)).get_type().Equals(ChessPiece.ROOK, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            Board BACK_BOARD = BOARD.backup();
                                            if (canMove(x1, y1, x2, 5, Player))
                                            {
                                                BOARD.movePiece(x1, y1, x2, y2);
                                                BOARD.movePiece(x1, y1, x2, 5);
                                                bool CanCastling = !(inCheck(Player));
                                                BOARD = BACK_BOARD;
                                                Console.WriteLine("Can roque!");
                                                return(CanCastling);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (x1 == 7 && y1 == 4 && x2 == 7 && y2 == 2)
                            {
                                if (LEFT_ROOK_PLAYER1_MOVED == false && BOARD.getPiece(7, 1).getClass2() == NullPiece.getClass() && BOARD.getPiece(7, 2).getClass2() == NullPiece.getClass() && BOARD.getPiece(7, 3).getClass2() == NullPiece.getClass())
                                {
                                    if (BOARD.getPiece(x1, 0).getClass2().Equals(ChessPiece.getClass()))
                                    {
                                        if (((ChessPiece)BOARD.getPiece(x1, 0)).PLAYER == Player && ((ChessPiece)BOARD.getPiece(x1, 7)).get_type().Equals(ChessPiece.ROOK, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            Board BACK_BOARD = BOARD.backup();
                                            if (canMove(x1, y1, x2, 3, Player))
                                            {
                                                BOARD.movePiece(x1, y1, x2, y2);
                                                BOARD.movePiece(x1, y1, x2, 3);
                                                bool CanCastling = !(inCheck(Player));
                                                BOARD = BACK_BOARD;
                                                Console.WriteLine("Can roque!");
                                                return(CanCastling);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }


                    if (Player == PLAYER2)
                    {
                        if (KING_PLAYER2_MOVED == false)
                        {
                            if (x1 == 0 && y1 == 4 && x2 == 0 && y2 == 6)
                            {
                                if (RIGHT_ROOK_PLAYER2_MOVED == false && BOARD.getPiece(0, 5).getClass2() == NullPiece.getClass() && BOARD.getPiece(0, 6).getClass2() == NullPiece.getClass())
                                {
                                    if (BOARD.getPiece(x1, 0).getClass2().Equals(ChessPiece.getClass()))
                                    {
                                        if (((ChessPiece)BOARD.getPiece(x1, 0)).PLAYER == Player && ((ChessPiece)BOARD.getPiece(x1, 0)).get_type().Equals(ChessPiece.ROOK, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            Board BACK_BOARD = BOARD.backup();
                                            if (canMove(x1, y1, x2, 5, Player))
                                            {
                                                BOARD.movePiece(x1, y1, x2, y2);
                                                BOARD.movePiece(x1, y1, x2, 5);
                                                bool CanCastling = !(inCheck(Player));
                                                BOARD = BACK_BOARD;
                                                Console.WriteLine("Can roque!");
                                                return(CanCastling);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (x1 == 0 && y1 == 4 && x2 == 0 && y2 == 2)
                            {
                                if (LEFT_ROOK_PLAYER1_MOVED == false && BOARD.getPiece(0, 1).getClass2() == NullPiece.getClass() && BOARD.getPiece(0, 2).getClass2() == NullPiece.getClass() && BOARD.getPiece(0, 3).getClass2() == NullPiece.getClass())
                                {
                                    if (BOARD.getPiece(x1, 0).getClass2().Equals(ChessPiece.getClass()))
                                    {
                                        if (((ChessPiece)BOARD.getPiece(x1, 0)).PLAYER == Player && ((ChessPiece)BOARD.getPiece(x1, 0)).get_type().Equals(ChessPiece.ROOK, StringComparison.CurrentCultureIgnoreCase))
                                        {
                                            Board BACK_BOARD = BOARD.backup();
                                            if (canMove(x1, y1, x2, 3, Player))
                                            {
                                                BOARD.movePiece(x1, y1, x2, y2);
                                                BOARD.movePiece(x1, y1, x2, 3);
                                                bool CanCastling = !(inCheck(Player));
                                                BOARD = BACK_BOARD;
                                                Console.WriteLine("Can roque!");
                                                return(CanCastling);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
        public override bool move(int x1, int y1, int x2, int y2, int Player)
        {
            bool  eat         = false;
            Piece eaten_piece = BOARD.getPiece(x2, y2);
            bool  CheckMate   = false;

            if (canMove(x1, y1, x2, y2, Player))
            {
                int x3 = x2;
                int y3 = y2;
                if ((y1 != y2) && eaten_piece.getClass2() == NullPiece.getClass() && ((ChessPiece)BOARD.getPiece(x1, y1)).get_type().Equals(ChessPiece.PAWN, StringComparison.CurrentCultureIgnoreCase))
                {
                    eaten_piece = BOARD.getPiece(x1, y2);
                    BOARD.removePiece(x1, y2);

                    x3 = x1;
                    y3 = y2;
                }
                if (eaten_piece.getClass2() != NullPiece.getClass())
                {
                    eat = true;
                }



                if ((x1 == 0 && y1 == 0) && (!LEFT_ROOK_PLAYER2_MOVED))
                {
                    LEFT_ROOK_PLAYER2_MOVED = true;
                }
                else if ((x1 == 0 && y1 == 7) && (!RIGHT_ROOK_PLAYER2_MOVED))
                {
                    RIGHT_ROOK_PLAYER2_MOVED = true;
                }
                else if ((x1 == 7 && y1 == 0) && (!LEFT_ROOK_PLAYER1_MOVED))
                {
                    LEFT_ROOK_PLAYER1_MOVED = true;
                }
                else if ((x1 == 7 && y1 == 7) && (!RIGHT_ROOK_PLAYER1_MOVED))
                {
                    RIGHT_ROOK_PLAYER1_MOVED = true;
                }

                if (((ChessPiece)BOARD.getPiece(x1, y1)).get_type().Equals(ChessPiece.KING, StringComparison.CurrentCultureIgnoreCase))
                {
                    if (Player == PLAYER1)
                    {
                        KING_PLAYER1_MOVED = true;
                    }
                    else
                    {
                        KING_PLAYER2_MOVED = true;
                    }
                }



                bool change_pawn = false;
                if (((ChessPiece)BOARD.getPiece(x1, y1)).get_type().Equals(ChessPiece.PAWN, StringComparison.CurrentCultureIgnoreCase))
                {
                    if (x2 == 0 || x2 == 7)
                    {
                        change_pawn = true;
                    }
                }


                if (x1 == 7 && y1 == 4 && ((ChessPiece)BOARD.getPiece(x1, y1)).get_type().Equals(ChessPiece.KING, StringComparison.CurrentCultureIgnoreCase) && Math.Abs(y2 - y1) > 1)
                {
                    if (y2 == 2)
                    {
                        BOARD.movePiece(7, 0, 7, 3);
                    }
                    else
                    {
                        BOARD.movePiece(7, 7, 7, 5);
                    }
                }
                else if (x1 == 0 && y1 == 4 && ((ChessPiece)BOARD.getPiece(x1, y1)).get_type().Equals(ChessPiece.KING, StringComparison.CurrentCultureIgnoreCase) && Math.Abs(y2 - y1) > 1)
                {
                    if (y2 == 2)
                    {
                        BOARD.movePiece(0, 0, 0, 3);
                    }
                    else
                    {
                        BOARD.movePiece(0, 7, 0, 5);
                    }
                }

                BOARD.movePiece(x1, y1, x2, y2);


                if (change_pawn)
                {
                    if (x2 == 0)
                    {
                        BOARD.addPiece(x2, y2, new ChessPiece("X", PLAYER1, ChessPiece.QUEEN));
                    }
                    else
                    {
                        BOARD.addPiece(x2, y2, new ChessPiece("O", PLAYER2, ChessPiece.QUEEN));
                    }
                }

                String CheckTag = "";
                if (Player == PLAYER1 && inCheck(PLAYER2))
                {
                    CheckTag = "<CHECK MESSAGE>PLAYER2 IN CHECK</CHECK MESSAGE>";
                }
                else if (Player == PLAYER2 && inCheck(PLAYER1))
                {
                    CheckTag = "<CHECK MESSAGE>PLAYER1 IN CHECK</CHECK MESSAGE>";
                }


                if (eat)
                {
                    LAST_ACTION = new MoveAndEatAction(x1, y1, x2, y2, BOARD.getPiece(x2, y2), eaten_piece, x3, y3);
                }
                else
                {
                    LAST_ACTION = new MoveAction(x1, y1, x2, y2, BOARD.getPiece(x2, y2));
                }


                if (ACTUAL_PLAYER == PLAYER1)
                {
                    ACTUAL_PLAYER = PLAYER2;
                }
                else
                {
                    ACTUAL_PLAYER = PLAYER1;
                }

                CheckMate = inCheckMate(ACTUAL_PLAYER);
                if (CheckMate)
                {
                    if (ACTUAL_PLAYER == PLAYER1)
                    {
                        CheckTag = "<CHECK MESSAGE>PLAYER1 IN CHECKMATE</CHECK MESSAGE>";
                        WINNER   = PLAYER2;
                    }
                    else
                    {
                        CheckTag = "<CHECK MESSAGE>PLAYER2 IN CHECKMATE</CHECK MESSAGE>";
                        WINNER   = PLAYER1;
                    }
                    GAME_ENDED = true;
                }
                LAST_MESSAGE = "<LAST ACTION>" + LAST_ACTION.action2String() + "</LAST ACTION>" + CheckTag;
                if (CheckMate)
                {
                    Console.WriteLine("   CheckMate: " + CheckMate);
                }
                return(true);
            }
            return(false);
        }
Beispiel #11
0
        public override bool canMove(int x1, int y1, int x2, int y2, int Player)
        {
            if (GAME_ENDED || WAITING_PLAYERS)
            {
                return(false);
            }
            if (Player != ACTUAL_PLAYER)
            {
                return(false);
            }

            if (!BOARD.validCell(x1, y1) || !BOARD.validCell(x2, y2))
            {
                return(false);
            }

            if (BOARD.getPiece(x1, y1).getClass2() == NullPiece.getClass())
            {
                return(false);
            }
            if (BOARD.getPiece(x2, y2).getClass2() != NullPiece.getClass())
            {
                return(false);
            }

            if (BOARD.getPiece(x1, y1).getClass2() == NullPiece.getClass())
            {
                return(false);
            }

            CheckersPiece P1 = (CheckersPiece)BOARD.getPiece(x1, y1);

            if (P1.getPlayer() != Player)
            {
                Console.WriteLine("player:" + P1.getPlayer());
                return(false);
            }



            if ((Math.Abs(x2 - x1) == 1 && Math.Abs(y2 - y1) == 1) && !EAT_MOVE)
            {
                if (P1.TYPE == CheckersPiece.CHECKER)
                {
                    return(true);
                }
                else if (P1.TYPE == CheckersPiece.SIMPLE)
                {
                    if (Player == PLAYER1)
                    {
                        if (x2 > x1)
                        {
                            return(true);
                        }
                    }
                    else if (Player == PLAYER2)
                    {
                        if (x2 < x1)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid player name: " + Player);
                    }
                }
                else
                {
                    Console.WriteLine("Invalid piece type: " + P1.TYPE);
                }
            }
            else
            {
                if ((Math.Abs(x2 - x1) == 2 && Math.Abs(y2 - y1) == 2) && (!EAT_MOVE || EAT_PIECE == BOARD.getPiece(x1, y1)))
                {
                    int x_adversary = x1 + (x2 - x1) / 2;
                    int y_adversary = y1 + (y2 - y1) / 2;
                    if (isAdversary((Piece)BOARD.getPiece(x_adversary, y_adversary), Player))
                    {
                        if (P1.TYPE == CheckersPiece.CHECKER)
                        {
                            if (canEat(x_adversary, y_adversary))
                            {
                                return(true);
                            }
                        }
                        else if (P1.TYPE == CheckersPiece.SIMPLE)
                        {
                            if (Player == PLAYER1)
                            {
                                if (x2 > x1)
                                {
                                    if (canEat(x_adversary, y_adversary))
                                    {
                                        return(true);
                                    }
                                }
                            }
                            else if (Player == PLAYER2)
                            {
                                if (x2 < x1)
                                {
                                    if (canEat(x_adversary, y_adversary))
                                    {
                                        return(true);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Invalid player name: " + Player);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Invalid piece type: " + P1.TYPE);
                        }
                    }
                }
            }
            return(false);
        }
        public void auxDisparLaser(int x, int y, String laser_orientation)
        {
            if (BOARD.validCell(x, y))
            {
                Console.Write(x + "," + y + " " + laser_orientation + " ");
                LAST_MESSAGE += x + "," + y + " " + laser_orientation + ";";
                Piece P1 = BOARD.getPiece(x, y);
                if (P1.getClass2() == NullPiece.getClass())
                {
                    if (laser_orientation.Equals("N", StringComparison.CurrentCultureIgnoreCase))
                    {
                        auxDisparLaser(x - 1, y, laser_orientation);
                    }
                    else if (laser_orientation.Equals("S", StringComparison.CurrentCultureIgnoreCase))
                    {
                        auxDisparLaser(x + 1, y, laser_orientation);
                    }
                    else if (laser_orientation.Equals("E", StringComparison.CurrentCultureIgnoreCase))
                    {
                        auxDisparLaser(x, y + 1, laser_orientation);
                    }
                    else if (laser_orientation.Equals("W", StringComparison.CurrentCultureIgnoreCase))
                    {
                        auxDisparLaser(x, y - 1, laser_orientation);
                    }
                    else
                    {
                        Console.WriteLine("ERROR invalid laser orientation - aux_dispar_laser");
                    }
                }
                else if (P1.getClass2() == DeflexionPiece.getClass())
                {
                    String type = ((DeflexionPiece)P1).get_type();
                    if ((type.Equals(DeflexionPiece.PHAROAH, StringComparison.CurrentCultureIgnoreCase)) || (type.Equals(DeflexionPiece.OBELISK, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        burn(x, y);
                        LAST_MESSAGE += P1.getString();
                    }
                    else
                    {
                        String ori = ((DeflexionPiece)P1).get_orientation();

                        String tag1 = "";
                        String tag2 = "";
                        if (laser_orientation.Equals("N", StringComparison.CurrentCultureIgnoreCase))
                        {
                            tag1 = "NE";
                            tag2 = "NW";
                        }
                        else if (laser_orientation.Equals("S", StringComparison.CurrentCultureIgnoreCase))
                        {
                            tag1 = "SE";
                            tag2 = "SW";
                        }
                        else if (laser_orientation.Equals("E", StringComparison.CurrentCultureIgnoreCase))
                        {
                            tag1 = "NE";
                            tag2 = "SE";
                        }
                        else if (laser_orientation.Equals("W", StringComparison.CurrentCultureIgnoreCase))
                        {
                            tag1 = "SW";
                            tag2 = "NW";
                        }

                        if (ori.Equals(tag1, StringComparison.CurrentCultureIgnoreCase) || ori.Equals(tag2, StringComparison.CurrentCultureIgnoreCase))
                        {
                            burn(x, y);
                            LAST_MESSAGE += P1.getString();
                        }
                        else
                        {
                            if ((laser_orientation.Equals("N", StringComparison.CurrentCultureIgnoreCase)) || (laser_orientation.Equals("S", StringComparison.CurrentCultureIgnoreCase)))
                            {
                                if (ori.Equals("NE", StringComparison.CurrentCultureIgnoreCase) || ori.Equals("SE", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    auxDisparLaser(x, y + 1, "E");
                                }
                                else if (ori.Equals("NW", StringComparison.CurrentCultureIgnoreCase) || ori.Equals("SW", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    auxDisparLaser(x, y - 1, "W");
                                }
                                else
                                {
                                    Console.WriteLine("ERROR invalid deflexion: " + laser_orientation + " - " + ori + "- aux_dispar_laser");
                                }
                            }
                            else if ((laser_orientation.Equals("E", StringComparison.CurrentCultureIgnoreCase)) || (laser_orientation.Equals("W", StringComparison.CurrentCultureIgnoreCase)))
                            {
                                if (ori.Equals("NE", StringComparison.CurrentCultureIgnoreCase) || ori.Equals("NW", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    auxDisparLaser(x - 1, y, "N");
                                }
                                else if (ori.Equals("SE", StringComparison.CurrentCultureIgnoreCase) || ori.Equals("SW", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    auxDisparLaser(x + 1, y, "S");
                                }
                                else
                                {
                                    Console.WriteLine("ERROR invalid deflexion2: " + laser_orientation + " - " + ori + "- aux_dispar_laser");
                                }
                            }
                            else
                            {
                                Console.WriteLine("ERROR invalid deflexion3: " + laser_orientation + " - " + ori + "- aux_dispar_laser");
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("ERROR invalid class piece type - aux_dispar_laser");
                }
            }
            else
            {
                Console.WriteLine("No piece burned.");
            }
        }
        public override bool canMove(int x1, int y1, int x2, int y2, int Player)
        {
            Console.WriteLine("Deflexion can move: " + x1 + " " + x2 + " " + y1 + " " + y2 + " " + Player + " " + PLAYER1 + " " + PLAYER2 + " " + GAME_ENDED);
            if (GAME_ENDED)
            {
                return(false);
            }

            if (CONFIRM_MOVE)
            {
                return(false);
            }

            if ((Math.Abs(x2 - x1) > 1 || Math.Abs(y2 - y1) > 1))
            {
                return(false);
            }

            if ((Math.Abs(x2 - x1) == 0 && Math.Abs(y2 - y1) == 0))
            {
                return(false);
            }

            if (Player != ACTUAL_PLAYER)
            {
                return(false);
            }

            if (!BOARD.validCell(x1, y1) || !BOARD.validCell(x2, y2))
            {
                return(false);
            }

            if (BOARD.getPiece(x1, y1).getClass2() == NullPiece.getClass())
            {
                return(false);
            }

            if (BOARD.getPiece(x2, y2).getClass2() != NullPiece.getClass())
            {
                Console.WriteLine("Moving deflexion2.1");
                if (!((DeflexionPiece)BOARD.getPiece(x1, y1)).get_type().Equals(DeflexionPiece.DJED, StringComparison.CurrentCultureIgnoreCase))
                {
                    Console.WriteLine("Moving deflexion2.2");
                    return(false);
                }
                else
                {
                    Console.WriteLine("Moving deflexion2.3");
                    String temp_type = ((DeflexionPiece)BOARD.getPiece(x2, y2)).get_type();
                    if ((temp_type.Equals(DeflexionPiece.DJED)) || (temp_type.Equals(DeflexionPiece.PHAROAH, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        Console.WriteLine("Moving deflexion4");
                        return(false);
                    }
                }
            }

            if (BOARD.getPiece(x1, y1).getClass2() == NullPiece.getClass())
            {
                return(false);
            }

            DeflexionPiece P1 = (DeflexionPiece)BOARD.getPiece(x1, y1);

            Console.WriteLine(Player + " " + P1.getPlayer());
            if (P1.getPlayer() != Player)
            {
                return(false);
            }


            if ((y2 == 0) && (P1.getPlayer() == PLAYER2))
            {
                return(false);
            }

            if ((y2 == 9) && (P1.getPlayer() == PLAYER1))
            {
                return(false);
            }

            return(true);
        }