예제 #1
0
        public void UpdateGraphInfo(StateVertex cur, StateVertex prev)
        {
            this.BeginInvoke(new MethodInvoker(delegate
            {
                this.curStateTextEdit.Text  = cur == null ? "" : $"S{cur.Number}";
                this.prevStateTextEdit.Text = prev == null ? "" : $"S{prev.Number}";

                this.lastEventTextEdit.Text = cur != null && prev != null ? $"{prev.Number}->{cur.Number}" : "";
            }));
        }
예제 #2
0
        public EnhancementGraph(IDeterministicPolicy <EnhancementState> policy, EnhancementState initialState, int iterations)
        {
            var nextStates = new HashSet <EnhancementState> {
                initialState
            };
            var allStates = new HashSet <EnhancementState>();

            while (iterations-- > 0)
            {
                var nextNextStates = new HashSet <EnhancementState>();
                foreach (var state in nextStates)
                {
                    var from = _graph.Vertices.SingleOrDefault(v => v.Label == state.ToString());
                    if (from == null)
                    {
                        from = new StateVertex(state);
                        _graph.AddVertex(from);
                    }

                    var action = policy[state];
                    if (action == null)
                    {
                        continue;
                    }

                    var actionStates = action[state].ToArray();
                    foreach (var s in actionStates)
                    {
                        var to = _graph.Vertices.SingleOrDefault(v => v.Label == s.ToString());
                        if (to == null)
                        {
                            to = new StateVertex(s);
                            _graph.AddVertex(to);
                        }

                        _graph.AddEdge(new ActionEdge(action)
                        {
                            Source = from,
                            Target = to,
                        });
                    }

                    nextNextStates.UnionWith(actionStates);
                }

                nextStates.Clear();
                foreach (var s in nextNextStates)
                {
                    if (allStates.Add(s))
                    {
                        nextStates.Add(s);
                    }
                }
            }
        }
예제 #3
0
        private void SetupStateChart(StateChart chart)
        {
            var bootState  = new StateVertex(diContainer.Instantiate <BootState>());
            var mapState   = new StateVertex(diContainer.Instantiate <LevelSelectionState>());
            var boardState = new StateVertex(diContainer.Instantiate <BoardState>());

            var editor = new StateMachineEditor(chart);

            editor.Initial().Transition().Target(mapState);
            bootState.Transition().Target(mapState);
            mapState.Event(GameStateEvents.StartLevelEvent).Target(boardState);
            boardState.Event(GameStateEvents.ExitBoardEvent).Target(mapState);
            mapState.Event(GameStateEvents.DisposedEvent).Target(editor.Final());
        }
예제 #4
0
        public void NextStateRandom()
        {
            _prevSelectedVertex = _selectedVertex;

            if (_selectedVertex == null)
            {
                _selectedVertex = _vertexList[new Random(DateTime.Now.Millisecond).Next(_vertexList.Count)];
            }
            else
            {
                int nextStateIndex = new Random(DateTime.Now.Millisecond).Next(_selectedVertex.Transitions.Count);
                _selectedVertex = _selectedVertex.Transitions[nextStateIndex];
            }

            DrawGraph();

            _parent.UpdateGraphInfo(_selectedVertex, _prevSelectedVertex);
        }
예제 #5
0
        private void DrawPanelMouseDown(object sender, MouseEventArgs e)
        {
            _prevSelectedVertex = _selectedVertex = null;
            if (e.Button == MouseButtons.Left)
            {
                foreach (var vert in _vertexList)
                {
                    var rect = vert.Rectangle;
                    if (e.X >= rect.X && e.X <= rect.X + rect.Width &&
                        e.Y >= rect.Y && e.Y <= rect.Y + rect.Height)
                    {
                        _selectedVertex = vert;
                        break;
                    }
                }
                DrawGraph();

                _parent.UpdateGraphInfo(_selectedVertex, _prevSelectedVertex);
            }
        }
예제 #6
0
 private void InitGraph(CommonMatrix vert, CommonMatrix state)
 {
     // Инициализация вершин и переходов
     _vertexList = StateVertex.GetVertexes(vert, GetRectForPoint);
     StateVertex.FillTransitions(_vertexList, state);
 }