Ejemplo n.º 1
0
        public void insertPieces()
        {
            for (int cont = 0; cont < 8; cont++)
            {
                BOARD.addPiece(1, cont, new ChessPiece("O", PLAYER2, ChessPiece.PAWN));
                BOARD.addPiece(6, cont, new ChessPiece("X", PLAYER1, ChessPiece.PAWN));
            }
            for (int cont = 0; cont < 2; cont++)
            {
                BOARD.addPiece(0, Math.Abs(7 * cont), new ChessPiece("O", PLAYER2, ChessPiece.ROOK));
                BOARD.addPiece(7, Math.Abs(7 * cont), new ChessPiece("X", PLAYER1, ChessPiece.ROOK));

                BOARD.addPiece(0, Math.Abs(7 * cont - 1), new ChessPiece("O", PLAYER2, ChessPiece.KNIGHT));
                BOARD.addPiece(7, Math.Abs(7 * cont - 1), new ChessPiece("X", PLAYER1, ChessPiece.KNIGHT));

                BOARD.addPiece(0, Math.Abs(7 * cont - 2), new ChessPiece("O", PLAYER2, ChessPiece.BISHOP));
                BOARD.addPiece(7, Math.Abs(7 * cont - 2), new ChessPiece("X", PLAYER1, ChessPiece.BISHOP));
            }

            BOARD.addPiece(0, 3, new ChessPiece("O", PLAYER2, ChessPiece.QUEEN));
            BOARD.addPiece(0, 4, new ChessPiece("O", PLAYER2, ChessPiece.KING));

            BOARD.addPiece(7, 3, new ChessPiece("X", PLAYER1, ChessPiece.QUEEN));
            BOARD.addPiece(7, 4, new ChessPiece("X", PLAYER1, ChessPiece.KING));
        }
        public override bool add(int x, int y, int Player)
        {
            TictactoePiece P = null;

            if (Player == PLAYER1)
            {
                P = new TictactoePiece("X", PLAYER1);
            }
            else if (Player == PLAYER2)
            {
                P = new TictactoePiece("O", PLAYER2);
            }
            else
            {
                Console.WriteLine("Invalid player: '" + Player + "'. Players: '" + PLAYER1 + "' and '" + PLAYER2 + "'.");
                return(false);
            }
            if (canAdd(x, y, (Piece)P))
            {
                if (BOARD.addPiece(x, y, (Piece)P))
                {
                }
                else
                {
                    Console.WriteLine("BLASFEMIA!!!");
                }
                if (gameEnded())
                {
                    Console.WriteLine("End game. Winner: " + WINNER);
                }
                CONT_ID++;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public void insertPieces()
        {
            for (int cont = 0; cont < 4; cont++)
            {
                BOARD.addPiece(0, cont * 2, new CheckersPiece("x", PLAYER1, CheckersPiece.SIMPLE));
                BOARD.addPiece(1, 1 + cont * 2, new CheckersPiece("x", PLAYER1, CheckersPiece.SIMPLE));
                BOARD.addPiece(2, cont * 2, new CheckersPiece("x", PLAYER1, CheckersPiece.SIMPLE));

                BOARD.addPiece(5, 1 + cont * 2, new CheckersPiece("o", PLAYER2, CheckersPiece.SIMPLE));
                BOARD.addPiece(6, cont * 2, new CheckersPiece("o", PLAYER2, CheckersPiece.SIMPLE));
                BOARD.addPiece(7, 1 + cont * 2, new CheckersPiece("o", PLAYER2, CheckersPiece.SIMPLE));
            }
        }
Ejemplo n.º 4
0
        public override bool add(int x, int y, int Player)
        {
            TictactoePiece P = null;

            if (Player == PLAYER1)
            {
                P = new TictactoePiece("+", PLAYER1);
            }
            else if (Player == PLAYER2)
            {
                P = new TictactoePiece("-", PLAYER2);
            }
            else
            {
                Console.WriteLine("Invalid player: '" + Player + "'. Players: '" + PLAYER1 + "' and '" + PLAYER2 + "'.");
                return(false);
            }
            if (canAdd(x, y, (Piece)P))
            {
                if (BOARD.addPiece(x, y, (Piece)P))
                {
                }
                else
                {
                    Console.WriteLine("BLASFEMIA!!!");
                }

                if ((BOARD.contPieces(new  TictactoePiece("", -1)) == 9) && WINNER == -1)
                {
                    DRAWN_GAME   = true;
                    GAME_ENDED   = true;
                    LAST_MESSAGE = "DRAWN GAME";
                }
                if (gameEnded())
                {
                    if (DRAWN_GAME)
                    {
                        Console.WriteLine("End game. " + LAST_MESSAGE);
                    }
                    else
                    {
                        Console.WriteLine("End game. Winner: " + WINNER);
                    }
                }
                CONT_ID++;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public override bool add(int x, int y, int Player)
        {
            NovoJogoPiece P = null;

            if (Player == PLAYER1)
            {
                P = new NovoJogoPiece("X", PLAYER1, NovoJogoPiece.PECA_X);
            }
            else if (Player == PLAYER2)
            {
                P = new NovoJogoPiece("O", PLAYER2, NovoJogoPiece.PECA_O);
            }
            else
            {
                Console.WriteLine("O Jogador que esta tentando jogar nao pertence ao jogo: '" + Player + "'. Jogadores no jogo: '" + PLAYER1 + "' e '" + PLAYER2 + "'.");
                return(false);
            }
            if (canAdd(x, y, (Piece)P))
            {
                if (!BOARD.addPiece(x, y, (Piece)P))
                {
                }
                else
                {
                    Console.WriteLine("Nao foi possivel adicionar a peca. Problema desconhecido.");
                }
                if ((BOARD.contPieces(new NovoJogoPiece("", -1, "")) == 9) && WINNER == -1)
                {
                    DRAWN_GAME   = true;
                    GAME_ENDED   = true;
                    LAST_MESSAGE = "VELHA";
                }
                if (gameEnded())
                {
                    if (DRAWN_GAME)
                    {
                        Console.WriteLine("Jogo encerrado. " + LAST_MESSAGE);
                    }
                    else
                    {
                        Console.WriteLine("Jogo encerrado. Vencedor: " + WINNER);
                    }
                }
                CONT_ID++;
                return(true);
            }
            return(false);
        }
        public void insertPieces()
        {
            for (int cont = 0; cont < 4; cont++)
            {
                BOARD.addPiece(3, 0, new DeflexionPiece("X", PLAYER1, DeflexionPiece.PYRAMID, "NE"));
                BOARD.addPiece(4, 0, new DeflexionPiece("X", PLAYER1, DeflexionPiece.PYRAMID, "SE"));
                BOARD.addPiece(1, 2, new DeflexionPiece("X", PLAYER1, DeflexionPiece.PYRAMID, "SW"));
                BOARD.addPiece(0, 7, new DeflexionPiece("X", PLAYER1, DeflexionPiece.PYRAMID, "SE"));
                BOARD.addPiece(3, 7, new DeflexionPiece("X", PLAYER1, DeflexionPiece.PYRAMID, "SE"));
                BOARD.addPiece(4, 7, new DeflexionPiece("X", PLAYER1, DeflexionPiece.PYRAMID, "NE"));
                BOARD.addPiece(5, 6, new DeflexionPiece("X", PLAYER1, DeflexionPiece.PYRAMID, "SE"));

                BOARD.addPiece(3, 4, new DeflexionPiece("X", PLAYER1, DeflexionPiece.DJED, "SW"));
                BOARD.addPiece(3, 5, new DeflexionPiece("X", PLAYER1, DeflexionPiece.DJED, "SE"));

                BOARD.addPiece(0, 4, new DeflexionPiece("X", PLAYER1, DeflexionPiece.OBELISK));
                BOARD.addPiece(0, 6, new DeflexionPiece("X", PLAYER1, DeflexionPiece.OBELISK));

                BOARD.addPiece(0, 5, new DeflexionPiece("X", PLAYER1, DeflexionPiece.PHAROAH));


                BOARD.addPiece(3, 2, new DeflexionPiece("O", PLAYER2, DeflexionPiece.PYRAMID, "SW"));
                BOARD.addPiece(4, 2, new DeflexionPiece("O", PLAYER2, DeflexionPiece.PYRAMID, "NW"));
                BOARD.addPiece(2, 3, new DeflexionPiece("O", PLAYER2, DeflexionPiece.PYRAMID, "NW"));
                BOARD.addPiece(3, 9, new DeflexionPiece("O", PLAYER2, DeflexionPiece.PYRAMID, "NW"));
                BOARD.addPiece(4, 9, new DeflexionPiece("O", PLAYER2, DeflexionPiece.PYRAMID, "SW"));
                BOARD.addPiece(6, 7, new DeflexionPiece("O", PLAYER2, DeflexionPiece.PYRAMID, "NE"));
                BOARD.addPiece(7, 2, new DeflexionPiece("O", PLAYER2, DeflexionPiece.PYRAMID, "NW"));

                BOARD.addPiece(4, 4, new DeflexionPiece("O", PLAYER2, DeflexionPiece.DJED, "NW"));
                BOARD.addPiece(4, 5, new DeflexionPiece("O", PLAYER2, DeflexionPiece.DJED, "NE"));

                BOARD.addPiece(7, 3, new DeflexionPiece("O", PLAYER2, DeflexionPiece.OBELISK));
                BOARD.addPiece(7, 5, new DeflexionPiece("O", PLAYER2, DeflexionPiece.OBELISK));

                BOARD.addPiece(7, 4, new DeflexionPiece("O", PLAYER2, DeflexionPiece.PHAROAH));
            }
        }
Ejemplo n.º 7
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);
        }