示例#1
0
        /// <summary>
        /// Работа ведется с ныннешнем состоянием поля OneRunTable
        /// </summary>
        /// <returns></returns>
        public BotAction MakeDecision()
        {
            var Relevance = InitializeDictinory <BotAction, double>();

            foreach (var key in Relevance)
            {
                for (int i = 0; i < CardRow; i++)
                {
                    for (int j = 0; j < CardColumn; j++)
                    {
                        Relevance[key.Key] += Math.Abs(OneRunTable[i, j].Value - KeyCard[key.Key].TakePlace((Motivate)i, (Direction)j));
                    }
                }
            }
            BotAction dicision = (BotAction)0;
            double    tempMin  = Relevance[dicision];

            foreach (var key in Relevance)
            {
                if (key.Value < tempMin)
                {
                    dicision = key.Key;
                }
            }
            return(dicision);
        }
示例#2
0
        public BotAction GetNextAction()
        {
            BotAction        act            = CurrentAction;
            List <BotAction> KnownBotAcions = GetPossibleActions(MaxThinkAboutDistance, MaxSupportedZChange);

            lock (KnownBotAcions)
            {
                if (KnownBotAcions.Count > 0)
                {
                    act = KnownBotAcions[0];// (BotAction)FindBestUsage(KnownBotAcions);
                }
                if (act == null)
                {
                    SimRegion R = Actor.GetSimRegion();
                    if (R == null)
                    {
                        return(new CommandAction(Actor, "anim shrug"));
                    }
                    Vector3d v3d =
                        R.LocalToGlobal(new Vector3(MyRandom.Next(250) + 5, MyRandom.Next(250) + 5,
                                                    Actor.SimPosition.Z));
                    Actor.Debug("MoveToLocation: " + Actor.DistanceVectorString(v3d));
                    SimPosition WP = SimWaypointImpl.CreateGlobal(v3d);
                    act = new MoveToLocation(Actor, WP);
                }
                return(act);
            }
        }
示例#3
0
 public void AddAction(BotAction action)
 {
     if (actionList.Find(x => x == action) == null)
     {
         actionList.Add(action);
     }
 }
示例#4
0
        public async Task UpdateBotAction(int id, BotAction botAction)
        {
            var entity = await GetBotAction(id);

            if (entity == null)
            {
                throw new InvalidOperationException($"Bot action id '{id}' not found.");
            }

            if (string.IsNullOrWhiteSpace(botAction.Command))
            {
                throw new UnprocessableEntityException("Command is required");
            }
            if (string.IsNullOrWhiteSpace(botAction.Action))
            {
                throw new UnprocessableEntityException("Action is required");
            }
            if (string.IsNullOrWhiteSpace(botAction.Parameters))
            {
                throw new UnprocessableEntityException("Parameters are required");
            }
            if (await db.BotActions.AnyAsync(x =>
                                             x.Id != id &&
                                             x.Command == botAction.Command))
            {
                throw new ConflictException("Bot command already exists");
            }

            db.Entry(entity).CurrentValues.SetValues(botAction);
            await db.SaveChangesAsync();
        }
示例#5
0
        public void UseAspect(BotMentalAspect someAspect)
        {
            try
            {
                if (someAspect is BotAction)
                {
                    BotAction act = (BotAction)someAspect;
                    act.InvokeReal();
                    return;
                }
                if (InDialogWith != null)
                {
                    Actor.TalkTo(InDialogWith, someAspect);
                    return;
                }

                if (someAspect is SimObject)
                {
                    SimObject someObject = (SimObject)someAspect;
                    DoBestUse(someObject);
                }
            }
            finally
            {
                //if (IsThinking)
                //    CurrentAction = this;
            }
        }
示例#6
0
        public override BotAction NextAction()
        {
            var result = new BotAction {
                Action = ActionType.Move
            };
            bool success = false;

            while (!success)
            {
                Direction direction;
                lock (_locker)
                {
                    direction = (Direction)random.Next(0, 4);
                }

                var target = GetDirection(direction, Position);

                if (World.Current.Map[target] != -1)
                {
                    result.Target = target;
                    success       = true;
                }
            }

            return(result);
        }
示例#7
0
        public void TurnAroud()
        {
            Action = BotAction.TurningAround;

            var target = TurnTarget;

            if (target == null)
            {
                target = Ball.Location;
            }

            var steerValue = Field.GetSteeringValueToward(Info, target);

            Controller.Steer     = steerValue;
            Controller.Handbrake = true;

            var range = .33;

            if (steerValue <= 0 + range && steerValue >= 0 - range)
            {
                TurnTarget           = null;
                Action               = BotAction.Default;
                Controller.Handbrake = false;
            }
        }
示例#8
0
        public IEnumerable <BotAction> GetActions()
        {
            var listActions = new List <BotAction>();

            var findAction = new BotAction()
            {
                CommandLine = Constants.CMD_CHROMECAST_FIND,
                Description = Constants.DESC_CHROMECAST_FIND,
                Category    = Constants.CAT_CHROMECAST,
                Execute     = async(parameters, log, currentReader, user, time) =>
                {
                    var result = await Find();

                    if (result == null || !result.Any())
                    {
                        return("Aucun récepteur trouvé");
                    }

                    return(string.Join("\n", result));
                }
            };

            listActions.Add(findAction);

            var selectAction = new BotAction()
            {
                CommandLine = Constants.CMD_CHROMECAST_SELECT,
                Description = Constants.DESC_CHROMECAST_SELECT,
                Category    = Constants.CAT_CHROMECAST,
                Execute     = async(parameters, log, currentReader, user, time) =>
                {
                    var name = string.Join(" ", parameters);
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        return($"La commande prend obligatoirement un paramètre, le nom du chrome cast");
                    }

                    var result = await Find();

                    if (result == null || !result.Any())
                    {
                        return("Aucun récepteur trouvé");
                    }

                    var resultSelect = await Select(name);

                    if (!resultSelect)
                    {
                        return($"Le récepteur avec le nom *{name}* n'a pas été trouvé");
                    }

                    return($"Le récepteur courant est maintenant *{name}*");
                }
            };

            listActions.Add(selectAction);

            return(listActions);
        }
示例#9
0
        protected BotAction DefineAction(string type, params string[] dataMembers)
        {
            var action = BotAction.Define(type, dataMembers);

            Actions.Add(action);

            return(action);
        }
示例#10
0
    public void MoveTo(Vector2i destination)
    {
        mStuckFrames = 0;

        Vector2i startTile = mMap.GetMapTileAtPoint(mAABB.Center - mAABB.HalfSize + Vector2.one * Map.cTileSize * 0.5f);

        if (mOnGround && !IsOnGroundAndFitsPos(startTile))
        {
            if (IsOnGroundAndFitsPos(new Vector2i(startTile.x + 1, startTile.y)))
            {
                startTile.x += 1;
            }
            else
            {
                startTile.x -= 1;
            }
        }

        var path = mMap.mPathFinder.FindPath(
            startTile,
            destination,
            Mathf.CeilToInt(mAABB.HalfSizeX / 8.0f),
            Mathf.CeilToInt(mAABB.HalfSizeY / 8.0f),
            (short)mMaxJumpHeight);


        mPath.Clear();

        if (path != null && path.Count > 1)
        {
            for (var i = path.Count - 1; i >= 0; --i)
            {
                mPath.Add(path[i]);
            }

            mCurrentNodeId = 1;

            //ChangeAction(BotAction.MoveTo);

            //mFramesOfJumping = GetJumpFramesForNode(0);
        }
        else
        {
            mCurrentNodeId = -1;

            if (mCurrentAction == BotAction.MoveTo)
            {
                mCurrentAction = BotAction.None;
            }
        }

        if (!Debug.isDebugBuild)
        {
            DrawPathLines();
        }
    }
示例#11
0
        private bool TryFindNewAction()
        {
            // if there is are any possible actions and there is no other action pending
            if (actionList.Count > 0 && _actionPathPending == false)
            {
                for (var i = 0; i < actionList.Count; i++)
                {
                    Debug.Assert(actionList[i] != null, "actiunea este nula"); // the action must not be null
                }
                var random = UnityEngine.Random.value;                         // sa schimb in random mai incolo
                actionList.Sort(CompareAction);                                // sort the action list based on the probability

                for (var i = 0; i < actionList.Count; i++)
                {
                    var action = actionList[i];
                    if (random < action.probability) // if the random satisfies
                    {
                        var place = action.place;
                        Debug.Log("trying to go to place <color=green> </color>" + place);
                        RandomShuffle(ActionPlace.Dictionary[place]); // random shuffle the possible targets
                        foreach (var possiblePlace in ActionPlace.Dictionary[place])
                        {
                            Debug.Assert(possiblePlace != null); // it must not be null
                            // the bot in there is null and is not occupied and is different from the last action
                            if (possiblePlace.occupied == false && possiblePlace.bot == null &&
                                possiblePlace != _lastPlace)
                            {
                                currentState           = State.AnyAction; // enter the any action state
                                possiblePlace.occupied = true;            // occupy the action
                                //possiblePlace.bot = this;
                                _lastPlace     = possiblePlace;
                                _currentAction = action; // set the currentAction

                                CurrentDestination =
                                    action.position +
                                    possiblePlace.transform.position; // set the destination to the relative pos
                                _agent.SetDestination(CurrentDestination);
                                Debug.Log(
                                    "<color=red>botul : " + name + " a reusit sa intre in actiunea : " +
                                    _currentAction.name + "</color>", this);
                                Debug.Log("<color=red>destinatia este</color>" + CurrentDestination, possiblePlace);
                                _actionPathPending = true;
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        //Debug.Log($"<color=red> " + action.name + "X</color>");
                    }
                }
            }

            return(false);
        }
示例#12
0
        public async Task <IActionResult> UpdateBotAction(int id, BotAction botAction)
        {
            if (botAction == null)
            {
                return(BadRequest());
            }

            await botService.UpdateBotAction(id, botAction);

            return(NoContent());
        }
示例#13
0
 public void RemoveAction(BotAction action)
 {
     if (actionList.Count == 0)
     {
         return;
     }
     if (actionList.Contains(action))
     {
         actionList.Remove(action);
     }
 }
示例#14
0
        public async Task <IActionResult> DeleteBotAction(BotAction botAction)
        {
            if (botAction == null)
            {
                return(BadRequest());
            }

            await botService.DeleteBotAction(botAction.Id);

            return(NoContent());
        }
示例#15
0
文件: BotQueue.cs 项目: dbeattie71/ak
        public BotAction Peek(int index)
        {
            if (index > _actions.Count - 1)
            {
                throw new Exception("Can't Peek because the index is greater than the number of actions in the queue.");
            }

            BotAction action = (BotAction)_actions[index];

            return(action);
        }
示例#16
0
 public WrapBot(string botName, int botTeam, int botIndex) : base(botName, botTeam, botIndex)
 {
     State        = BotState.Kickoff;
     Action       = BotAction.Default;
     Controller   = new Controller();
     Field        = new FieldService(botTeam);
     Ball         = new BallWrapper();
     Info         = new PlayerWrapper();
     Game         = new GameWrapper();
     DesiredState = null;
 }
示例#17
0
 internal static void DoWork_SelectMobFail()
 {
     if (_status != BotStatus.Start)
     {
         return;
     }
     _mobId = 0;
     Views.BindingFrom.WriteLine("[DoWork_MobDie] => call [SelectNextMobForAttack]");
     _BotAction = BotAction.SelectFall;
     Bot.BotInput.SelectMobForAttack();
 }
示例#18
0
        public static void ChangeBotAction(BotAction botAction)
        {
            listBox.SelectedItem = botAction;

            int index = listBox.SelectedIndex;

            actions.Remove((BotAction)listBox.SelectedItem);

            actions.Insert(index, botAction);

            RefreshListBox();
        }
示例#19
0
文件: Map.cs 项目: SotaIT/botcombat
 public Coordinates GetMoveDestination(BotAction botAction, int x, int y)
 {
     switch (botAction)
     {
     case BotAction.MoveUp:
     case BotAction.MoveRight:
     case BotAction.MoveDown:
     case BotAction.MoveLeft:
         return(GetDestination(botAction.ToDirection(), x, y));
     }
     return(new Coordinates(x, y));
 }
        private void HandleBotAction(Guid botId, BotAction action, BotInformation botInformation)
        {
            switch (action.Action)
            {
            case ActionType.Move:
                MoveBot(botId, action.Target, botInformation);
                break;

            case ActionType.Attack:
                AttackBot(botId, action.Target, botInformation);
                break;
            }
        }
示例#21
0
文件: BotQueue.cs 项目: dbeattie71/ak
        public BotAction Dequeue()
        {
            if (_actions.Count == 0)
            {
                throw new Exception("Can't dequeue botaction because the queue is empty.");
            }

            BotAction action = (BotAction)_actions[0];

            _actions.RemoveAt(0);

            return(action);
        }
示例#22
0
        private static void RequestSelectMob(uint mobId)
        {
            Views.BindingFrom.WriteLine("[RequestSelectMob] id = " + mobId);
            //Create packet  select mob
            Packet packet = new Packet(0x7045);//CLIENT_OBJECTSELECT

            packet.WriteUInt32(mobId);

            //Sent packet  select mob
            ThreadProxy.Proxy.SendPacketToAgentRemote(packet);

            //change Bot Action
            _BotAction = BotAction.RequestSelectMob;
        }
示例#23
0
        private void Button_DOWN_Click(object sender, RoutedEventArgs e)
        {
            if (ListBox_Actions.SelectedIndex != -1 && ListBox_Actions.SelectedIndex != actions.Count - 1)
            {
                int newIndex = ListBox_Actions.SelectedIndex + 1;

                BotAction botAction = (BotAction)ListBox_Actions.SelectedItem;

                actions.Remove(botAction);

                actions.Insert(newIndex, botAction);

                RefreshListBox();
            }
        }
示例#24
0
        public void SetAction(MessageEventArgs messageEventArgs, string workName)
        {
            if (messageEventArgs.Message.Type != MessageType.Text)
            {
                return;
            }
            var methods = GetMethod <ActionAttribute>();

            foreach (var method in methods) // iterate through all found methods
            {
                var attributes = method.GetCustomAttributes(false);

                var attributesAll = attributes.Select(CheckWork).ToList();
                attributesAll.RemoveAll(x => x == null);

                var attribute = attributesAll.FirstOrDefault();
                if (attribute == null)
                {
                    return;
                }

                if (attribute.WorkName != workName)
                {
                    continue;
                }

                var botAction = new BotAction(messageEventArgs.Message.Text);

                Log.Information(string.Join("", new List <string>()
                {
                    $"Message Id: {messageEventArgs.Message.MessageId}, ",
                    $"Text: {messageEventArgs.Message.Text}, ",
                    $"Chat: {messageEventArgs.Message.Chat.Id}, ",
                    $"From: {messageEventArgs.Message.From}, ",
                    $"Type: {messageEventArgs.Message.Type}, ",
                    $"Date: {messageEventArgs.Message.Date}, ",
                    $"Work: {workName}, ",
                }));

                var obj = Activator.CreateInstance(method.DeclaringType); // Instantiate the class
                method.Invoke(obj, parameters: new object[]
                {
                    new TextParams(action: botAction, message: messageEventArgs.Message),
                }
                              ); // invoke the method
                break;
            }
        }
示例#25
0
        public void Aerial()
        {
            Action           = BotAction.Aerial;
            Controller.Jump  = true;
            Controller.Boost = true;
            Controller.Steer = Field.GetSteeringValueToward(Info, Ball.Location);
            Controller.Pitch = Field.GetPitchValueToward(Info, Ball.Location);

            if (Ball.Location.Z < GameValuesService.BallRadius * 3)
            {
                Action           = BotAction.Default;
                Controller.Jump  = false;
                Controller.Boost = false;
                Controller.Pitch = 0;
            }
        }
示例#26
0
        internal static void DoWork_SelectMobSuccess(uint mobId)
        {
            if (_status != BotStatus.Start)
            {
                return;
            }

            if (mobId != _mobId)
            {
                Views.BindingFrom.WriteLine("[DoWork_SelectMobSuccess] => call [AttackThisMob] id = " + mobId);
                _BotAction = BotAction.SelectSuccess;
                _mobId     = mobId;

                Bot.BotInput.AttackThisMob(mobId);
            }
        }
示例#27
0
        protected void FlipAction()
        {
            if (SpecificFlipDirection)
            {
                Controller.Steer = FlipDirection;
            }
            Controller.Boost = false;

            if (JustDoubleJumped)
            {
                Controller.Jump = false;
                if (Info.HasWheelContact)
                {
                    JustDoubleJumped = false;
                    Controller.Pitch = 0;
                    Flipping         = false;
                    Action           = BotAction.Default;
                }
                return;
            }

            if (Flipping == false)
            {
                //Perform the First Flip
                Action           = BotAction.Flipping;
                Flipping         = true;
                Controller.Pitch = -1;
                Controller.Jump  = true;
                JustJumped       = true;
                return;
            }

            if (JustJumped)
            {
                //Releasing first Jump
                Controller.Jump = false;
                JustJumped      = false;
                return;
            }
            else
            {
                Controller.Pitch = -1;
                Controller.Jump  = true;
                JustDoubleJumped = true;
                return;
            }
        }
示例#28
0
        public IEnumerable <BotAction> GetActions()
        {
            var listActions = new List <BotAction>();

            var weekAction = new BotAction()
            {
                CommandLine = Constants.CMD_WEATHER_WEEK,
                Description = Constants.DESC_WEATHER_WEEK,
                Category    = Constants.CAT_WEATHER,
                Execute     = async(parameters, log, currentReader, user, time) =>
                {
                    var week = await GetCurrentWeek(parameters.Length >= 1?parameters[0] : null);

                    if (week == null)
                    {
                        return($"Une erreur est survenue");
                    }

                    return(week);
                }
            };

            listActions.Add(weekAction);

            var dayAction = new BotAction()
            {
                CommandLine = Constants.CMD_WEATHER_DAY,
                Description = Constants.DESC_WEATHER_DAY,
                Category    = Constants.CAT_WEATHER,
                Execute     = async(parameters, log, currentReader, user, time) =>
                {
                    var day = await GetCurrentDay(parameters.Length >= 1?parameters[0] : null);

                    if (day == null)
                    {
                        return($"Une erreur est survenue");
                    }

                    return(day);
                }
            };

            listActions.Add(dayAction);

            return(listActions);
        }
示例#29
0
        public async Task <IActionResult> CreateBotAction(BotAction botAction)
        {
            if (botAction == null)
            {
                return(BadRequest());
            }

            if (botService.GetBotActions().Any(x => x.Command == botAction.Command
                                               & x.Parameters == botAction.Parameters))
            {
                return(UnprocessableEntity("Bot action already added"));
            }

            await botService.CreateBotAction(botAction);

            return(CreatedAtRoute("GetBotAction", new { id = botAction.Id }, botAction));
        }
示例#30
0
        private bool IsAvatarActive()
        {
            BotAction cur = Actor.CurrentAction;

            if (cur == this)
            {
                return(false);
            }
            if (cur == null)
            {
                return(false);
            }
            if (cur == CurrentAction)
            {
                return(false);
            }
            return(true);
        }
 public void ChangeAction(BotAction newAction)
 {
     mCurrentAction = newAction;
 }
    public void MoveTo(Vector2i destination)
    {
        mStuckFrames = 0;

        Vector2i startTile = mMap.GetMapTileAtPoint(mAABB.Center - mAABB.HalfSize + Vector2.one * Map.cTileSize * 0.5f);
        
        if (mOnGround && !IsOnGroundAndFitsPos(startTile))
        {
            if (IsOnGroundAndFitsPos(new Vector2i(startTile.x + 1, startTile.y)))
                startTile.x += 1;
            else
                startTile.x -= 1;
        }

        var path =  mMap.mPathFinder.FindPath(
                        startTile, 
                        destination,
                        Mathf.CeilToInt(mAABB.HalfSizeX / 8.0f), 
                        Mathf.CeilToInt(mAABB.HalfSizeY / 8.0f), 
                        (short)mMaxJumpHeight);


        mPath.Clear();

        if (path != null && path.Count > 1)
        {
            for (var i = path.Count - 1; i >= 0; --i)
                mPath.Add(path[i]);

            mCurrentNodeId = 1;

            ChangeAction(BotAction.MoveTo);

            mFramesOfJumping = GetJumpFramesForNode(0);
        }
        else
        {
            mCurrentNodeId = -1;

            if (mCurrentAction == BotAction.MoveTo)
                mCurrentAction = BotAction.None;
        }

        if (!Debug.isDebugBuild)
            DrawPathLines();
    }
    public void OnFoundPath(List<Vector2i> path)
    {
        mJumpingUpStairsRight = false;
        mJumpingUpStairsLeft = false;

        mPath.Clear();

        if (path != null && path.Count > 1)
        {
            for (var i = path.Count - 1; i >= 0; --i)
                mPath.Add(path[i]);

            //mCurrentNodeId = 1;

            //if (mCurrentNodeId < mPath.Count)
            //    mFramesOfJumping = GetJumpFrameCount(mPath[mCurrentNodeId].y - mPath[mCurrentNodeId - 1].y);

            //ChangeAction(BotAction.MoveTo);
        }
        else
        {
            mCurrentNodeId = -1;

            if (mCurrentAction == BotAction.MoveTo)
                mCurrentAction = BotAction.None;
        }

        if (!Debug.isDebugBuild)
            DrawPathLines();
    }