Exemplo n.º 1
0
        /// <summary>
        /// Returns all robot actions that will be performed by this card in correct order.
        /// </summary>
        /// <param name="direction">Actual direction of robot to define actions.</param>
        /// <returns>Well ordered actions performed by this card.</returns>
        public IEnumerable <RoboAction> GetActionList(Direction direction)
        {
            switch (CardType)
            {
            case CardType.MoveBackwardOne:
                return(new RoboAction[] { new RoboMovement(RoboRotation.Rotate(direction, Rotation.Around)) });

            case CardType.MoveForwardOne:
                return(new RoboAction[] { new RoboMovement(direction) });

            case CardType.MoveForwardTwo:
                return(new RoboAction[] { new RoboMovement(direction), new RoboMovement(direction) });

            case CardType.MoveForwardThree:
                return(new RoboAction[] { new RoboMovement(direction), new RoboMovement(direction), new RoboMovement(direction) });

            case CardType.TurnLeft:
                return(new RoboAction[] { new RoboRotation(Rotation.Left) });

            case CardType.TurnRight:
                return(new RoboAction[] { new RoboRotation(Rotation.Right) });

            case CardType.TurnAround:
                return(new RoboAction[] { new RoboRotation(Rotation.Around) });

            case CardType.Undefined:
                return(new RoboAction[] { RoboAction.EMPTY });
            }
            return(new RoboAction[] { RoboAction.EMPTY });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs a robot movement.
        /// </summary>
        /// <param name="position">Position of the robot before the action.</param>
        /// <param name="board">Board to perform action on.</param>
        /// <returns>Position of robot after performing the action.</returns>
        public override RoboPosition PerformAction(RoboPosition position, RoboBoard board)
        {
            RoboField field = board.GetField(position);

            if (!field.CanLeave(this.Direction))
            {
                return(position);
            }

            RoboPosition result = PerformAction(position);

            RoboField neighbor = board.GetField(result);

            if (neighbor == null || !neighbor.CanEnter(RoboRotation.Rotate(this.Direction, Rotation.Around)))
            {
                return(position);
            }

            return(result);
        }
Exemplo n.º 3
0
 public override RoboAction OnRobotRotate(ActionPhase actionPhase, RoboRotation rotation, RoboPosition position)
 {
     //TODO: this is not done well -> should return rotation, but doing so leads to infinite call of this behavior
     position.Direction = rotation.Rotate(position.Direction);
     return(base.OnRobotRotate(actionPhase, rotation, position));
 }
Exemplo n.º 4
0
 public virtual RoboAction OnRobotRotate(ActionPhase actionPhase, RoboRotation rotation, RoboPosition position)
 {
     return(null);
 }