Пример #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);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        ///To calculate the horizontal movements of a horse, we need to go 2 cells north and south.
        ///For the valid vertical 2 cell movements, we can then go horizontal as a half location.
        /// </summary>
        /// <returns></returns>
        private List <Position> GetHorizontalTwoAndHalfMovements(IDirection direction)
        {
            var verticalPositions = new List <Position>();
            var northIndex        = CurrentPosition.Row + 2;

            if (northIndex.IsValidMovement() == true)
            {
                verticalPositions.Add(new Position(northIndex, CurrentPosition.Column));
            }
            var southIndex = CurrentPosition.Row - 2;

            if (southIndex.IsValidMovement() == true)
            {
                verticalPositions.Add(new Position(southIndex, CurrentPosition.Column));
            }
            var horizontalMovements = new List <Position>();

            verticalPositions.ForEach(x =>
            {
                horizontalMovements.AddRange(direction.GetEastPositions(x, 1));
                horizontalMovements.AddRange(direction.GetWestPositions(x, 1));
            });
            return(horizontalMovements);
        }