示例#1
0
文件: Azura.cs 项目: air-labs/CVARC
        private IEnumerable <Command> RepairStarship()
        {
            var nearSocket = Map.Walls.Where(x => x.Type.ToLower().Contains(color)).OrderBy(GetDistance).FirstOrDefault();

            if (nearSocket == null)
            {
                return(new Command[0]);
            }
            var path = PathSearcher.FindPath(Map, OurCoordinates, nearSocket.DiscreteCoordinate);

            if (path.Length == 0)
            {
                if (Map.CurrentPosition.X - nearSocket.AbsoluteCoordinate.X > Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Left));
                }
                if (Map.CurrentPosition.X - nearSocket.AbsoluteCoordinate.X < -Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Right));
                }
                if (Map.CurrentPosition.Y - nearSocket.AbsoluteCoordinate.Y > Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Down));
                }
                if (Map.CurrentPosition.Y - nearSocket.AbsoluteCoordinate.Y < -Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Up));
                }
                hasDetail = false;
                return(new[] { Command.Act(CommandAction.Release) });
            }
            return(RobotLocator.GetCommandsByDirection(path.First()));
        }
示例#2
0
文件: Azura.cs 项目: air-labs/CVARC
        private IEnumerable <Command> GripDetail()
        {
            var nearDetail = Map.Details.OrderBy(GetDistance).FirstOrDefault();

            if (nearDetail == null)
            {
                return(new Command[0]);
            }
            color = nearDetail.Type.Split(new[] { "Detail" }, StringSplitOptions.None).First().ToLower();
            var path = PathSearcher.FindPath(Map, OurCoordinates, nearDetail.DiscreteCoordinate);

            hasDetail = path.Length == 0;
            return(hasDetail ? new[] { Command.Act(CommandAction.Grip) } : RobotLocator.GetCommandsByDirection(path.First()));
        }
示例#3
0
    public void Execute(Command command)
    {
        if (command.IsValid())
        {
            if (CurrentCommand != null)
            {
                CurrentCommand.DoBeforeLeaving();
            }

            //For new Command
            CurrentCommand = command;
            command.DoBeforeEntering();
            command.Act();
        }
    }