Ejemplo n.º 1
0
        public override List <string> GetAvailableMoves()
        {
            List <string> availibleMoves = new List <string>();

            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    int movementReturn = Move(new int[] { x, y }, false);
                    if (movementReturn == 0 || movementReturn == 6)
                    {
                        availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(x + 97)) }{ Math.Abs(y - 8) }");
                    }
                }
            }

            bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1;

            if (inCheck)
            {
                List <string> remove = new List <string>();
                int           xPos   = XPosition;
                int           yPos   = YPosition;

                foreach (string move in availibleMoves)
                {
                    Piece tempPiece         = ChessController.Board.GetPieceAt(move);
                    Piece currentPieceClone = new Knight((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos);

                    //BUG: Pawn promotes if can block or take to last row
                    XPosition = xPos;
                    YPosition = yPos;
                    Move(ChessController.ConvertToXY(move), true);

                    if (ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1)
                    {
                        remove.Add(move);
                    }

                    ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone;
                    ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece;
                }

                foreach (string move in remove)
                {
                    availibleMoves.Remove(move);
                }

                XPosition = xPos;
                YPosition = yPos;
            }

            if (!availibleMoves.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"))
            {
                availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }");
            }

            return(availibleMoves);
        }
Ejemplo n.º 2
0
        public List <string> GetAvailableMoves(bool isQueen)
        {
            List <string> availibleMoves = new List <string>();

            //int xIter = 0;
            //int yIter = 0;
            //for (int x = XPosition; x < 8; x++)
            //{
            //    xIter++;
            //    for (int y = YPosition; y < 8; y++)
            //    {
            //        yIter++;
            //        if (xIter == yIter)
            //        {
            //            if ()
            //            {
            //                availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(x + 97)) }{ y + 1}");

            //            }
            //        }
            //    }
            //}

            //xIter = 0;
            //yIter = 0;
            //for (int x = XPosition; x < 8; x++)
            //{
            //    xIter++;
            //    for (int y = YPosition; y >= 0; y--)
            //    {
            //        yIter++;
            //        if (xIter == yIter)
            //        {

            //        }
            //    }
            //}

            //xIter = 0;
            //yIter = 0;
            //for (int x = XPosition; x >= 0; x--)
            //{
            //    xIter++;
            //    for (int y = YPosition; y < 8; y++)
            //    {
            //        yIter++;
            //        if (xIter == yIter)
            //        {

            //        }
            //    }
            //}

            //xIter = 0;
            //yIter = 0;
            //for (int x = XPosition; x >= 0; x--)
            //{
            //    xIter++;
            //    for (int y = YPosition; y >= 0; y--)
            //    {
            //        yIter++;
            //        if (xIter == yIter)
            //        {

            //        }
            //    }
            //}

            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    if (Math.Abs(x - XPosition) == Math.Abs(y - YPosition))
                    {
                        int checkMovement = Move(new int[] { x, y }, false);
                        if (checkMovement == 0 || checkMovement == 6)
                        {
                            availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(x + 97)) }{ Math.Abs(y - 8) }");
                        }
                    }
                }
            }

            bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1;

            if (inCheck && !isQueen)
            {
                List <string> remove = new List <string>();
                int           xPos   = XPosition;
                int           yPos   = YPosition;

                foreach (string move in availibleMoves)
                {
                    Piece tempPiece         = ChessController.Board.GetPieceAt(move);
                    Piece currentPieceClone = new Bishop((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos);

                    //BUG: Pawn promotes if can block or take to last row
                    XPosition = xPos;
                    YPosition = yPos;
                    Move(ChessController.ConvertToXY(move), true);

                    if (ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1)
                    {
                        remove.Add(move);
                    }

                    ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone;
                    ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece;
                }

                foreach (string move in remove)
                {
                    availibleMoves.Remove(move);
                }

                XPosition = xPos;
                YPosition = yPos;
            }

            if (!availibleMoves.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"))
            {
                availibleMoves.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }");
            }

            return(availibleMoves);
        }
Ejemplo n.º 3
0
        public Piece GetPieceAt(string move)
        {
            int[] pos = ChessController.ConvertToXY(move);

            return(gameSpace[pos[0], pos[1]]);
        }
Ejemplo n.º 4
0
        public override List <string> GetAvailableMoves()
        {
            Rook          tempRook    = new Rook(char.IsLower(GetSymbol()) ? "White" : "Black", XPosition, YPosition);
            List <string> rookMoves   = tempRook.GetAvailableMoves(true);
            Bishop        tempBishop  = new Bishop(char.IsLower(GetSymbol()) ? "White" : "Black", XPosition, YPosition);
            List <string> bishopMoves = tempBishop.GetAvailableMoves(true);
            List <string> moves       = new List <string>();

            foreach (string move in rookMoves)
            {
                moves.Add(move);
            }

            foreach (string move in bishopMoves)
            {
                if (!moves.Contains(move))
                {
                    moves.Add(move);
                }
            }

            bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1;

            if (inCheck)
            {
                List <string> remove = new List <string>();
                int           xPos   = XPosition;
                int           yPos   = YPosition;

                foreach (string move in moves)
                {
                    Piece tempPiece         = ChessController.Board.GetPieceAt(move);
                    Piece currentPieceClone = new Queen((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos);

                    //BUG: Pawn promotes if can block or take to last row
                    XPosition = xPos;
                    YPosition = yPos;
                    Move(ChessController.ConvertToXY(move), true);
                    int[] isKingInCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite);

                    if (isKingInCheck[2] == 1)
                    {
                        remove.Add(move);
                    }

                    ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone;
                    ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece;
                }

                foreach (string move in remove)
                {
                    moves.Remove(move);
                }

                XPosition = xPos;
                YPosition = yPos;
            }

            if (!moves.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"))
            {
                moves.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }");
            }

            return(moves);
        }
Ejemplo n.º 5
0
        public List <string> GetAvailableMoves(bool isQueen)
        {
            List <string> movablePositions = new List <string>();

            for (int i = 0; i < 8; i++)
            {
                if (i != XPosition)
                {
                    int[] pos = new int[2] {
                        i, YPosition
                    };

                    if (Move(pos, false) == 0 || Move(pos, false) == 6)
                    {
                        movablePositions.Add($"{ Convert.ToString(Convert.ToChar(pos[0] + 97)) }{ Math.Abs(pos[1] - 8) }");
                    }
                }
                else
                {
                    for (int j = 0; j < 8; j++)
                    {
                        int[] pos = new int[2] {
                            XPosition, j
                        };

                        if (Move(pos, false) == 0 || Move(pos, false) == 6)
                        {
                            movablePositions.Add($"{ Convert.ToString(Convert.ToChar(pos[0] + 97)) }{ Math.Abs(pos[1] - 8) }");
                        }
                    }
                }
            }

            bool inCheck = ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1;

            if (inCheck && !isQueen)
            {
                List <string> remove = new List <string>();
                int           xPos   = XPosition;
                int           yPos   = YPosition;

                foreach (string move in movablePositions)
                {
                    Piece tempPiece         = ChessController.Board.GetPieceAt(move);
                    Piece currentPieceClone = new Rook((char.IsLower(GetSymbol()) ? "White" : "Black"), xPos, yPos);

                    //BUG: Pawn promotes if can block or take to last row
                    XPosition = xPos;
                    YPosition = yPos;
                    Move(ChessController.ConvertToXY(move), true);

                    if (ChessController.Board.IsKingInCheck(ChessController.IsWhite)[2] == 1)
                    {
                        remove.Add(move);
                    }

                    ChessController.Board.gameSpace[xPos, yPos] = currentPieceClone;
                    ChessController.Board.gameSpace[ChessController.ConvertToXY(move)[0], ChessController.ConvertToXY(move)[1]] = tempPiece;
                }

                foreach (string move in remove)
                {
                    movablePositions.Remove(move);
                }

                XPosition = xPos;
                YPosition = yPos;
            }

            if (!movablePositions.Contains($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }"))
            {
                movablePositions.Add($"{ Convert.ToString(Convert.ToChar(XPosition + 97)) }{ Math.Abs(YPosition - 8) }");
            }

            return(movablePositions);
        }