예제 #1
0
        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 burn(int x, int y)
        {
            Console.WriteLine("Burning: " + x + "," + y);
            Console.WriteLine(BOARD.getPiece(x, y).getClass2());
            if (BOARD.getPiece(x, y).getClass2() == DeflexionPiece.getClass())
            {
                String deleted_type   = ((DeflexionPiece)BOARD.getPiece(x, y)).get_type();
                int    deleted_player = ((DeflexionPiece)BOARD.getPiece(x, y)).getPlayer();
                if (BOARD.removePiece(x, y))
                {
                    if (deleted_type.Equals(DeflexionPiece.PHAROAH, StringComparison.CurrentCultureIgnoreCase))
                    {
                        GAME_ENDED = true;
                        if (deleted_player == PLAYER1)
                        {
                            WINNER = PLAYER2;
                        }
                        else if (deleted_player == PLAYER2)
                        {
                            WINNER = PLAYER1;
                        }
                        else
                        {
                            Console.WriteLine("Invalid player - burn end game");
                        }

                        Console.WriteLine("End game. Winner: " + WINNER);
                    }
                    CONT_ID++;
                    return(true);
                }
            }
            return(false);
        }
예제 #3
0
 public bool eat(int x, int y)
 {
     if (BOARD.getPiece(x, y).getClass2() == ChessPiece.getClass())
     {
         if (BOARD.removePiece(x, y))
         {
             if (gameEnded())
             {
                 Console.WriteLine("End game. Winner: " + WINNER);
             }
             return(true);
         }
     }
     return(false);
 }
예제 #4
0
        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);
        }