コード例 #1
0
ファイル: Agent.cs プロジェクト: MortenRoemer/Strategize
        public void Tick(TContext context)
        {
            if (!_locked)
            {
                var nextAction = _queuedActions.PeekMax().Item;

                if (!nextAction.Equals(CurrentAction))
                {
                    CurrentAction?.OnFinish(context);
                    CurrentAction = nextAction;
                    CurrentAction?.OnEnter(context);
                }
            }

            if (CurrentAction is null)
            {
                return;
            }

            var result = CurrentAction.OnTick(context);

            switch (result)
            {
            case ActionResult.Yield:
                _locked = false;
                break;

            case ActionResult.Reconsider:
                _locked = false;
                Consider(CurrentAction.Strategy, context);
                break;

            case ActionResult.Continue:
                _locked = true;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }