예제 #1
0
        public static bool ValidateMovement(this Piece piece, MoveAttempt moveAttempt)
        {
            bool valid = false;

            switch (piece.Name)
            {
            case "tower":
                valid = Rook.ValidateMovement(piece, moveAttempt);
                break;

            case "knight":
                valid = Knight.ValidateMovement(piece, moveAttempt);
                break;

            case "bishop":
                valid = Bishop.ValidateMovement(piece, moveAttempt);
                break;

            case "queen":
                valid = Queen.ValidateMovement(piece, moveAttempt);
                break;

            case "king":
                valid = King.ValidateMovement(piece, moveAttempt);
                break;

            case "pawn":
                valid = Pawn.ValidateMovement(piece, moveAttempt);
                break;
            }
            return(valid);
        }
예제 #2
0
        public static List <string> GetPossibleVaildCoordinates(Piece piece, MoveAttempt moveAttempt)
        {
            string currentHorizontalCoordinate = piece.CurrentSquare.HorizontalCoordinate;
            int    currentVerticalCoordinate   = piece.CurrentSquare.VerticalCoordinate;

            List <string> possibleValidCoordinates = new List <string>();
            Type          type = typeof(BoardHelpers.HorizontalCoordinates);
            string        maxAscendingHorizontalCoordinate  = Enum.GetName(type, (int)Enum.Parse(type, currentHorizontalCoordinate) + 2);
            string        minAscendingHorizontalCoordinate  = Enum.GetName(type, (int)Enum.Parse(type, currentHorizontalCoordinate) + 1);
            string        maxDescendingHorizontalCoordinate = Enum.GetName(type, (int)Enum.Parse(type, currentHorizontalCoordinate) - 2);
            string        minDescendingHorizontalCoordinate = Enum.GetName(type, (int)Enum.Parse(type, currentHorizontalCoordinate) - 1);
            int           maxAscendingVerticalCoordinate    = currentVerticalCoordinate + 2;
            int           minAscendingVerticalCoordinate    = currentVerticalCoordinate + 1;
            int           maxDescendingVerticalCoordinate   = currentVerticalCoordinate - 2;
            int           minDescendingVerticalCoordinate   = currentVerticalCoordinate - 1;

            possibleValidCoordinates.Add($"{minAscendingHorizontalCoordinate}{maxAscendingVerticalCoordinate}");
            possibleValidCoordinates.Add($"{maxAscendingHorizontalCoordinate}{minAscendingVerticalCoordinate}");
            possibleValidCoordinates.Add($"{maxAscendingHorizontalCoordinate}{minDescendingVerticalCoordinate}");
            possibleValidCoordinates.Add($"{minAscendingHorizontalCoordinate}{maxDescendingVerticalCoordinate}");
            possibleValidCoordinates.Add($"{minDescendingHorizontalCoordinate}{maxDescendingVerticalCoordinate}");
            possibleValidCoordinates.Add($"{maxDescendingHorizontalCoordinate}{minDescendingVerticalCoordinate}");
            possibleValidCoordinates.Add($"{maxDescendingHorizontalCoordinate}{minAscendingVerticalCoordinate}");
            possibleValidCoordinates.Add($"{minDescendingHorizontalCoordinate}{maxAscendingVerticalCoordinate}");
            return(possibleValidCoordinates);
        }
예제 #3
0
        public static bool ValidateMovement(Piece piece, MoveAttempt moveAttempt)
        {
            List <string> possibleValidCoordinates = GetPossibleVaildCoordinates(piece, moveAttempt);

            if (MoveCoordinatesAreValid(moveAttempt, possibleValidCoordinates))
            {
                if (AnyObstructions(moveAttempt))
                {
                    return(false);
                }

                return(true);
            }
            return(false);
        }
예제 #4
0
 public static bool ValidateMovement(Piece piece, MoveAttempt moveAttempt)
 {
     throw new NotImplementedException();
 }
예제 #5
0
        public static bool ValidateMovement(Piece piece, MoveAttempt moveAttempt)
        {
            char currentHorizontalIndex = moveAttempt.CurrentCoordinates.Substring(1, 1).ToCharArray()[0];
            int  currentVerticalIndex   = Int32.Parse(moveAttempt.CurrentCoordinates.Substring(0, 1));
            char newHorizontalIndex     = moveAttempt.NewCoordinates.Substring(1, 1).ToCharArray()[0];
            int  newVerticalIndex       = Int32.Parse(moveAttempt.NewCoordinates.Substring(0, 1));

            bool verticalMove   = (currentVerticalIndex != newVerticalIndex) && (currentHorizontalIndex == newHorizontalIndex);
            bool horizontalMove = (currentHorizontalIndex != newHorizontalIndex) && (currentVerticalIndex == newVerticalIndex);

            if (!verticalMove && !horizontalMove)
            {
                return(false);
            }
            else
            {
                bool pieceInPath = false;
                int  index       = 0;
                if (verticalMove)
                {
                    bool positiveMove = currentVerticalIndex < newVerticalIndex;
                    while (!pieceInPath)
                    {
                        string otherPieceLocation        = moveAttempt.PiecePlacementMap[index];
                        int    otherPieceVerticalIndex   = Int32.Parse(otherPieceLocation.Substring(0, 1));
                        char   otherPieceHorizontalIndex = otherPieceLocation.Substring(1, 1).ToCharArray()[0];
                        if (otherPieceHorizontalIndex == currentHorizontalIndex)
                        {
                            if (positiveMove)
                            {
                                if (otherPieceVerticalIndex < newVerticalIndex)
                                {
                                    pieceInPath = true;
                                }
                            }
                            else
                            {
                                if (otherPieceVerticalIndex > newVerticalIndex)
                                {
                                    pieceInPath = true;
                                }
                            }
                        }
                        index++;
                    }
                }
                else
                {
                    bool ascendingMove = currentHorizontalIndex < newHorizontalIndex;
                    while (!pieceInPath)
                    {
                        string otherPieceLocation        = moveAttempt.PiecePlacementMap[index];
                        int    otherPieceVerticalIndex   = Int32.Parse(otherPieceLocation.Substring(0, 1));
                        char   otherPieceHorizontalIndex = otherPieceLocation.Substring(1, 1).ToCharArray()[0];
                        if (otherPieceVerticalIndex == currentVerticalIndex)
                        {
                            if (ascendingMove)
                            {
                                if (otherPieceHorizontalIndex < newHorizontalIndex)
                                {
                                    pieceInPath = true;
                                }
                            }
                            else
                            {
                                if (otherPieceHorizontalIndex > newHorizontalIndex)
                                {
                                    pieceInPath = true;
                                }
                            }
                        }
                        index++;
                    }
                }
                return(pieceInPath ? false : true);
            }
        }
예제 #6
0
 public static bool ValidateMovement(Piece piece, MoveAttempt moveAttempt)
 {
     return(true);
 }
예제 #7
0
 private static bool AnyObstructions(MoveAttempt moveAttempt)
 {
     return(moveAttempt.PiecePlacementMap.Contains(moveAttempt.NewCoordinates));
 }
예제 #8
0
 private static bool MoveCoordinatesAreValid(MoveAttempt moveAttempt, List <string> possibleCoordinates) =>
 possibleCoordinates.Contains(moveAttempt.NewCoordinates);