Exemple #1
0
        private void SetDirections(CommandDirection letterRL)
        {
            AxisDirectionModel axisDirectModel = new AxisDirectionModel();

            axisDirectModel       = directionObj.GetNewDirection(letterRL, RoverCompassDirection);
            RoverCompassDirection = axisDirectModel.compassDirection;  //N-E-S-W
            AxisOfMotion          = axisDirectModel.axisDirection;
        }
Exemple #2
0
        public AxisDirectionModel GetNewDirection(CommandDirection command, CompassDirections direction)
        {
            AxisDirectionModel modelTemp = new AxisDirectionModel();

            modelTemp.compassDirection = GetNewCompassPoint(command, direction);
            modelTemp.axisDirection    = GetNewAxis(modelTemp.compassDirection);
            return(modelTemp);
        }
Exemple #3
0
 public CommandElement(CommandDirection direction, CommandButton button, Int32?triggertime, Boolean helddown, Boolean nothingelse)
 {
     Direction        = direction;
     Buttons          = button;
     TriggerOnRelease = triggertime;
     HeldDown         = helddown;
     NothingElse      = nothingelse;
     Hash             = Direction.GetHashCode() ^ Buttons.GetHashCode() ^ TriggerOnRelease.GetValueOrDefault(0).GetHashCode() ^ HeldDown.GetHashCode() ^ NothingElse.GetHashCode();
     MatchHash1       = BuildHash1();
     MatchHash2       = BuildHash2();
 }
Exemple #4
0
 private CompassDirections GetNewCompassPoint(CommandDirection command, CompassDirections direction)
 {
     if (command == CommandDirection.Right)
     {
         return(GetCompassDirectionTurnRight(direction));                                   //Turn Right
     }
     else
     {
         return(GetCompassDirectionTurnLeft(direction)); //Turn Left
     }
 }
Exemple #5
0
        private CommandDirection GetCommandFromLetter(char charCommand)
        {
            CommandDirection commandDir = CommandDirection.Move;

            switch (charCommand)
            {
            case 'R':
                commandDir = CommandDirection.Right;
                break;

            case 'L':
                commandDir = CommandDirection.Left;
                break;

            case 'M':
                commandDir = CommandDirection.Move;
                break;

            default:
                break;
            }
            return(commandDir);
        }
Exemple #6
0
        public virtual ICommandResult PropogateExecuted(ICommand command, CommandDirection direction) {
            command.Result = this.Run(CommandAttributeType.Executed, command, command.Result.CommandResultType);

            IList<ICoreController> propogationList = direction == CommandDirection.Tunnel ? this.TunnelExecutableObjects(command) : this.BubbleExecutableObjects(command);

            if (propogationList != null) {
                foreach (CoreController executable in propogationList) {
                    if (executable != null) {
                        command.Result = executable.PropogateExecuted(command, direction);
                    }
                }
            }

            return command.Result;
        }
Exemple #7
0
        public virtual ICommandResult PropogateHandler(ICommand command, CommandDirection direction) {
            command.Result = this.Run(CommandAttributeType.Handler, command, CommandResultType.Continue);

            if (command.Result.CommandResultType == CommandResultType.Continue) {
                IList<ICoreController> propogationList = direction == CommandDirection.Tunnel ? this.TunnelExecutableObjects(command) : this.BubbleExecutableObjects(command);

                for (int offset = 0; propogationList != null && offset < propogationList.Count && command.Result.CommandResultType == CommandResultType.Continue; offset++) {
                    if (propogationList[offset] != null) {
                        command.Result = propogationList[offset].PropogateHandler(command, direction);
                    }
                }
            }

            return command.Result;
        }
Exemple #8
0
 public CommandNameAttribute(string name, CommandDirection direction, ProtocolVersion minimumVersion, int length = -1) : base(length)
 {
     Name           = name;
     Direction      = direction;
     MinimumVersion = minimumVersion;
 }
Exemple #9
0
 public CommandNameAttribute(string name, CommandDirection direction, int length = -1) : this(name, direction, ProtocolVersion.Minimum, length)
 {
 }
Exemple #10
0
        public override ICommandResult PropogateHandler(ICommand command, CommandDirection direction) {
            if (this.PropogateHandlerCallback != null) this.PropogateHandlerCallback(command);

            return base.PropogateHandler(command, direction);
        }
        public override ICommandResult PropogateExecuted(ICommand command, CommandDirection direction) {
            if (direction == CommandDirection.Bubble && command.Scope != null && command.Scope.ConnectionGuid == this.ConnectionModel.ConnectionGuid) {
                // We've bubbled up far enough, time to tunnel down this connection to find our result.
                return base.PropogateExecuted(command, CommandDirection.Tunnel);
            }

            return base.PropogateExecuted(command, direction);
        }
Exemple #12
0
        private void MoveToNewPostion(CommandDirection newDirection)
        {
            switch (newDirection)
            {
                case CommandDirection.MoveForward:
                    Position[0] = Position[0] - 1;
                    break;
                case CommandDirection.TurnLeft:
                    Position[1] = Position[1] - 1;

                    break;
                case CommandDirection.TurnRight:
                    Position[1] = Position[1] + 1;
                    break;
                case CommandDirection.MoveInReverse:
                    Position[0] = Position[0] + 1;
                    break;

            }
            if (Position[0] < 0)
                Position[0] = 0;
            if (Position[1] < 0)
                Position[1] = 0;

            Position = new double[2]{Position[0],Position[1]};
            try
            {
                lock (RobotContol.ConsoleLock)
                {
                    //Console.SetCursorPosition((int) Position[0], (int) Position[1]);
                    //Console.Write('.');
                }
            }
            catch
            {
            }

            UpdateHeading();
        }
Exemple #13
0
        public void Turn(CommandDirection newDirection)
        {
            CurrentDirection = newDirection;
            Seconds++;
            //if (newDirection == RobotDirection.Rest)
            //{
            //    Rests++;
            //    Fuel = 200;
            //    return;
            //}
            //if (Fuel > 0)
            //{
            //    Fuel -= 1;
            //}

            if (!CanGoInDirection(newDirection))
            {
                return;
            }
            MoveToNewPostion(newDirection);
            OnPositionChanged1(new Position(Position[0],Position[1]));
            DistanceToDestination = CalculateDistance();

            if (Altitude < 0)
                Altitude = 0;
        }
Exemple #14
0
        public bool CanGoInDirection(CommandDirection newDirection)
        {
            var pos = new double[2]{Position[0],Position[1]};
            switch (newDirection)
            {
                case CommandDirection.MoveForward:
                    pos[0] = pos[0] - 1;
                    break;
                case CommandDirection.TurnLeft:
                    pos[1] = pos[1] - 1;

                    break;
                case CommandDirection.TurnRight:
                    pos[1] = pos[1] + 1;
                    break;
                case CommandDirection.MoveInReverse:
                    pos[0] = pos[0] + 1;
                    break;
            }
            if (pos[0] < 0)
                pos[0] = 0;
            if (pos[1] < 0)
                pos[1] = 0;

            var warpos =(from p in RobotContol.Warehouse.Positions where p.X == pos[0] && p.Y == pos[1] select p).FirstOrDefault();
            if (warpos == null)
                return false;
            switch (warpos.MapMode)
            {
                case MapMode.ObstructionMode:
                    return false;
                case MapMode.PersonMode:
                    return false;
                case MapMode.StorageMode:
                    if (Destination[0] == pos[0] && Destination[1] == pos[1])
                        return true;
                    if (StartPosition[0] == pos[0] && StartPosition[1] == pos[1])
                        return true;
                    return false;
                case MapMode.PickupMode:
                    if (Destination[0] == pos[0] && Destination[1] == pos[1])
                        return true;
                    if (StartPosition[0] == pos[0] && StartPosition[1] == pos[1])
                        return true;
                    return false;
                case MapMode.ShipMode:
                    if (Destination[0] == pos[0] && Destination[1] == pos[1])
                        return true;
                    if (StartPosition[0] == pos[0] && StartPosition[1] == pos[1])
                        return true;
                    return false;
                default:
                    return true;
            }
        }
        // Captures all executed commands, seeing if this async conroller is waiting for a command to have been executed.
        public override ICommandResult PropogateExecuted(ICommand command, CommandDirection direction) {
            AsynchronousCommandModel asynchronousCommandModel = null;

            // If we are waiting for it and we have removed the executed wrapper successfully.
            if (this.AsyncStateModel.ExecutedCommandsPool.TryRemove(command.CommandGuid, out asynchronousCommandModel) == true) {
                Task.Factory.StartNew(() => asynchronousCommandModel.OnResult(command.Result));
            }

            return base.PropogateExecuted(command, direction);
        }
        public override ICommandResult PropogatePreview(ICommand command, CommandDirection direction) {
            ICommandResult synchronousResult = null;

            // If we're bubbling and we have not seen this command yet
            if (direction == CommandDirection.Bubble && this.AsyncStateModel.IsKnown(command.CommandGuid) == false) {
                AutoResetEvent resultWait = new AutoResetEvent(false);

                this.BeginBubble(command, result => {
                    synchronousResult = result;

                    resultWait.Set();
                });

                // Wait here until we have a result to return to the plugin AppDomain.
                resultWait.WaitOne();
            }
            else {
                synchronousResult = base.PropogatePreview(command, direction);
            }

            return synchronousResult;
        }
Exemple #17
0
 public HandlerStateInput CommandToInput(CommandDirection direction, Command command)
 {
     return(( HandlerStateInput )(direction + _commandIndex[command]));
 }
Exemple #18
0
        ReadOnlyList <CommandElement> ParseCommandText(String text)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            List <CommandElement> elements = new List <CommandElement>();

            CommandElement lastelement = null;

            foreach (String token in text.Split(','))
            {
                if (String.IsNullOrEmpty(token) == true)
                {
                    continue;
                }

                Boolean          helddown    = false;
                Boolean          nothingelse = false;
                Int32?           triggertime = null;
                CommandDirection dir         = CommandDirection.None;
                CommandButton    buttons     = CommandButton.None;

                if (token.IndexOf('~') != -1)
                {
                    Int32 time  = 0;
                    Match match = m_numberregex.Match(token);
                    if (match.Success == true)
                    {
                        Int32.TryParse(match.Groups[1].Value, out time);
                    }

                    triggertime = time;
                }

                if (token.IndexOf('/') != -1)
                {
                    helddown = true;
                }

                if (token.IndexOf('>') != -1)
                {
                    nothingelse = true;
                }

                if (token.IndexOf("$B") != -1)
                {
                    dir = CommandDirection.B4Way;
                }
                else if (token.IndexOf("$U") != -1)
                {
                    dir = CommandDirection.U4Way;
                }
                else if (token.IndexOf("$F") != -1)
                {
                    dir = CommandDirection.F4Way;
                }
                else if (token.IndexOf("$D") != -1)
                {
                    dir = CommandDirection.D4Way;
                }
                else if (token.IndexOf("DB") != -1)
                {
                    dir = CommandDirection.DB;
                }
                else if (token.IndexOf("DF") != -1)
                {
                    dir = CommandDirection.DF;
                }
                else if (token.IndexOf("UF") != -1)
                {
                    dir = CommandDirection.UF;
                }
                else if (token.IndexOf("UF") != -1)
                {
                    dir = CommandDirection.UF;
                }
                else if (token.IndexOf("D+B") != -1)
                {
                    dir = CommandDirection.DB;
                }
                else if (token.IndexOf("D+F") != -1)
                {
                    dir = CommandDirection.DF;
                }
                else if (token.IndexOf("U+B") != -1)
                {
                    dir = CommandDirection.UB;
                }
                else if (token.IndexOf("U+F") != -1)
                {
                    dir = CommandDirection.UF;
                }
                else if (token.IndexOf("D") != -1)
                {
                    dir = CommandDirection.D;
                }
                else if (token.IndexOf("F") != -1)
                {
                    dir = CommandDirection.F;
                }
                else if (token.IndexOf("U") != -1)
                {
                    dir = CommandDirection.U;
                }
                else if (token.IndexOf("B") != -1)
                {
                    dir = CommandDirection.B;
                }

                if (token.IndexOf("a") != -1)
                {
                    buttons |= CommandButton.A;
                }
                if (token.IndexOf("b") != -1)
                {
                    buttons |= CommandButton.B;
                }
                if (token.IndexOf("c") != -1)
                {
                    buttons |= CommandButton.C;
                }
                if (token.IndexOf("x") != -1)
                {
                    buttons |= CommandButton.X;
                }
                if (token.IndexOf("y") != -1)
                {
                    buttons |= CommandButton.Y;
                }
                if (token.IndexOf("z") != -1)
                {
                    buttons |= CommandButton.Z;
                }
                if (token.IndexOf("s") != -1)
                {
                    buttons |= CommandButton.Taunt;
                }

                CommandElement element = new CommandElement(dir, buttons, triggertime, helddown, nothingelse);

                if (lastelement != null && SuccessiveDirectionCheck(lastelement, element) == true)
                {
                    CommandElement newelement1 = new CommandElement(element.Direction, CommandButton.None, 0, false, true);
                    CommandElement newelement2 = new CommandElement(element.Direction, CommandButton.None, null, false, true);

                    elements.Add(newelement1);
                    elements.Add(newelement2);
                }
                else
                {
                    elements.Add(element);
                }

                lastelement = element;
            }

            return(new ReadOnlyList <CommandElement>(elements));
        }