Exemple #1
0
        public override List <Position> GetPossiblePositions(IDirection direction)
        {
            var possibleOutcomes = new List <Position>();

            possibleOutcomes.AddRange(direction.GetEastPositions(CurrentPosition, Constants.ChessBoardUpperLimit));
            possibleOutcomes.AddRange(direction.GetWestPositions(CurrentPosition, Constants.ChessBoardUpperLimit));
            possibleOutcomes.AddRange(direction.GetNorthPositions(CurrentPosition, Constants.ChessBoardUpperLimit));
            possibleOutcomes.AddRange(direction.GetSouthPositions(CurrentPosition, Constants.ChessBoardUpperLimit));
            return(possibleOutcomes);
        }
Exemple #2
0
 /// <summary>
 /// Pawn can move only forward by one cell.
 /// White pawn can move forward from A to H as per chess boards location.
 /// Black pawn can move from H to A as per chess boards default location.
 /// </summary>
 /// <param name="initialPosition"></param>
 /// <returns></returns>
 public override List <Position> GetPossiblePositions(IDirection direction)
 {
     if (Color == PieceColours.White)
     {
         return(direction.GetNorthPositions(CurrentPosition, 1));
     }
     else
     {
         return(direction.GetSouthPositions(CurrentPosition, 1));
     }
 }
Exemple #3
0
        /// <summary>
        /// This gives possible movements of King.
        /// King can move only 1 step at a time in all 8 directions (horizontal, vertical and diagonal)
        /// </summary>
        /// <param name="initialPosition"></param>
        /// <returns></returns>
        public override List <Position> GetPossiblePositions(IDirection direction)
        {
            var possibleOutcomes = new List <Position>();

            possibleOutcomes.AddRange(direction.GetEastPositions(CurrentPosition, 1));
            possibleOutcomes.AddRange(direction.GetWestPositions(CurrentPosition, 1));
            possibleOutcomes.AddRange(direction.GetNorthPositions(CurrentPosition, 1));
            possibleOutcomes.AddRange(direction.GetSouthPositions(CurrentPosition, 1));
            possibleOutcomes.AddRange(direction.GetNorthEastPositions(CurrentPosition, 1));
            possibleOutcomes.AddRange(direction.GetNorthWestPositions(CurrentPosition, 1));
            possibleOutcomes.AddRange(direction.GetSouthEastPositions(CurrentPosition, 1));
            possibleOutcomes.AddRange(direction.GetSouthWestPositions(CurrentPosition, 1));
            return(possibleOutcomes);
        }
Exemple #4
0
        /// <summary>
        ///To calculate the vertical movements of a horse, we need to go 2 cells east and west.
        ///For the valid horizontal 2 cell movements, we can then go vertical as a half movement.
        /// </summary>
        /// <param name="initialPosition"></param>
        /// <returns></returns>
        private List <Position> GetVerticalTwoAndHalfMovements(IDirection direction)
        {
            var horizontalPositions = new List <Position>();
            var eastIndex           = CurrentPosition.Column + 2;

            if (eastIndex.IsValidMovement() == true)
            {
                horizontalPositions.Add(new Position(CurrentPosition.Row, eastIndex));
            }
            var westIndex = CurrentPosition.Column - 2;

            if (westIndex.IsValidMovement() == true)
            {
                horizontalPositions.Add(new Position(CurrentPosition.Row, westIndex));
            }
            var verticalMovements = new List <Position>();

            horizontalPositions.ForEach(x =>
            {
                verticalMovements.AddRange(direction.GetNorthPositions(x, 1));
                verticalMovements.AddRange(direction.GetSouthPositions(x, 1));
            });
            return(verticalMovements);
        }