Пример #1
0
        /// <summary>
        /// エージェントの行動
        /// </summary>
        /// <returns></returns>
        private async Task ActAgentAsync()
        {
            await InvokeAsync(() =>
            {
                if (EnvMaze.Cells[Agent.CurrentLocate.X, Agent.CurrentLocate.Y].IsGoal)
                {
                    MazeCellViews[Agent.CurrentLocate.X, Agent.CurrentLocate.Y].CellCssClass = CSS_CLASS_PATH;
                    Agent.EndOneLearning();
                }
                else
                {
                    ActAgent();

                    if (IndexData.IsStopWhenGoal && EnvMaze.Cells[Agent.CurrentLocate.X, Agent.CurrentLocate.Y].IsGoal)
                    {
                        ActTimer.Stop();
                    }

                    if (EnvMaze.Cells[Agent.CurrentLocate.X, Agent.CurrentLocate.Y].IsGoal && Agent.ActCount == EnvMaze.ShortestStep)
                    {
                        IndexData.AgentStateMessage = "最短経路に到達しました。";
                        if (IndexData.IsStopWhenBestRoot)
                        {
                            ActTimer.Stop();
                        }
                    }

                    this.StateHasChanged();
                }
            });
        }
Пример #2
0
        /// <summary>
        /// 指定回数ゴールするまで行動する
        /// </summary>
        public void SkipGoals()
        {
            if (ActTimer == null)
            {
                return;
            }

            ActTimer.Stop();

            for (int i = 0; i < IndexData.SkipGoalCount; i++)
            {
                while (true)
                {
                    ActAgent();

                    if (EnvMaze.Cells[Agent.CurrentLocate.X, Agent.CurrentLocate.Y].IsGoal)
                    {
                        // 自動学習再開後にゴール処理が実行されるので、最後のゴール時のみゴール処理を行わない
                        if (i + 1 < IndexData.SkipGoalCount)
                        {
                            Agent.EndOneLearning();
                        }

                        break;
                    }
                }
            }

            if (!IndexData.IsStopWhenGoal)
            {
                ActTimer.Start();
            }
        }
Пример #3
0
        /// <summary>
        /// 指定回数行動を進める
        /// </summary>
        public void SkipActions()
        {
            if (ActTimer == null)
            {
                return;
            }

            ActTimer.Stop();

            for (int i = 0; i < IndexData.SkipActCount; i++)
            {
                ActAgent();

                if (EnvMaze.Cells[Agent.CurrentLocate.X, Agent.CurrentLocate.Y].IsGoal)
                {
                    if (IndexData.IsStopWhenGoal)
                    {
                        return;
                    }

                    break;
                }
            }

            ActTimer.Start();
        }
Пример #4
0
 /// <summary>
 /// 学習一時停止
 /// </summary>
 public void StopLearning()
 {
     if (ActTimer != null)
     {
         ActTimer.Stop();
     }
 }
Пример #5
0
        /// <summary>
        /// エージェントを削除する
        /// </summary>
        public void ClearAgent()
        {
            if (Agent != null)
            {
                Agent = null;
            }

            if (ActTimer != null)
            {
                ActTimer.Stop();
                ActTimer.Dispose();
                ActTimer = null;
            }

            IndexData.AgentStateMessage = string.Empty;
            InitializeMazeView();
        }
Пример #6
0
        /// <summary>
        /// 学習開始
        /// </summary>
        public void StartLearning()
        {
            if (Agent == null)
            {
                SetAgent();
            }

            if (ActTimer == null)
            {
                ActTimer          = new Timer(IndexData.AnimationInterval);
                ActTimer.Elapsed += (sender, e) =>
                {
                    ActAgentAsync().Wait();
                };
            }

            ActTimer.Start();
        }