Ejemplo n.º 1
0
        public void Load(BehaviourGraph graph)
        {
            if (graph == null)
            {
                return;
            }

            _graph = graph;

            DeleteElements(edges.ToList());
            DeleteElements(nodes.ToList());
            Properties.Clear();
            Blackboard.Clear();

            foreach (var variable in graph.Variables)
            {
                AddExposedProperty(new ExposedProperty
                {
                    Name     = variable.Name,
                    Type     = variable.Type,
                    IsGlobal = variable.IsGlobal
                });
            }

            NodeDeserializer.Deserialize(graph.BehaviorSource.TaskData, this);
        }
Ejemplo n.º 2
0
        public void SerializeFourLevelTree()
        {
            var node = new Node {
                ratio      = { aCount = 1, anCount = 11 },
                SortedKids = new[] {
                    new Node {
                        c          = 'b',
                        ratio      = { aCount = 5, anCount = 0 },
                        SortedKids = new[] {
                            new Node {
                                c          = 'c',
                                ratio      = { aCount = 3, anCount = 4 },
                                SortedKids = new[] {
                                    new Node {
                                        c     = 'd',
                                        ratio = { aCount = 0x100, anCount = 0x80 }
                                    },
                                },
                            },
                            new Node {
                                c     = 'u',
                                ratio = { aCount = 2, anCount = 15 }
                            },
                        },
                    },
                }
            };
            const string serializedNode = @"1;b;1;b5;;2;c3;4;1;d74;3k;;u2;f;;";

            Assert.Equal(serializedNode, NodeSerializer.SerializeDense(node));
            Assert.Equal(node, NodeDeserializer.DeserializeDense(serializedNode), NodeEqualityComparer.Instance);
        }
Ejemplo n.º 3
0
        static void Simplify(string input)
        {
            var newLookup = NodeDeserializer.DeserializeDense(File.ReadAllText(input, Encoding.UTF8)).Simplify(5).UnmarkUnsure(3);

            Console.WriteLine("Simplified dense representation on next line:");
            Console.WriteLine(ObjectToCode.PlainObjectToCode(NodeSerializer.SerializeDense(newLookup)));
            Console.WriteLine();
            Console.WriteLine("Simplified no-statistics dense representation on next line:");
            Console.WriteLine(ObjectToCode.PlainObjectToCode(NodeSerializer.SerializeDenseNoStats(newLookup)));
        }
Ejemplo n.º 4
0
        public void SingleNodeWorks()
        {
            var node = new Node {
                ratio = { aCount = 0x2468ad, anCount = 0x12345 }
            };
            const string serializedNode = @"1f54d;1lj9;;";

            Assert.Equal(serializedNode, NodeSerializer.SerializeDense(node));
            Assert.Equal(node, NodeDeserializer.DeserializeDense(serializedNode), NodeEqualityComparer.Instance);
        }
Ejemplo n.º 5
0
        public void RootNodeWithKidsWorks()
        {
            var node = new Node {
                ratio      = { aCount = 1, anCount = 11 },
                SortedKids = new[] {
                    new Node {
                        c     = 'b',
                        ratio = { aCount = 5, anCount = 0 },
                    },
                    new Node {
                        c     = 'u',
                        ratio = { aCount = 2, anCount = 15 },
                    },
                }
            };

            const string serializedNode = @"1;b;2;b5;;;u2;f;;";

            Assert.Equal(serializedNode, NodeSerializer.SerializeDense(node));
            var deserialized = NodeDeserializer.DeserializeDense(serializedNode);

            Assert.Equal(node, deserialized, NodeEqualityComparer.Instance);
        }