Esempio n. 1
0
        public override ExecutionResult Execute(SuperMetroidModel model, InGameState inGameState, int times = 1, bool usePreviousRoom = false)
        {
            IEnumerable <int> visitedNodeIds = inGameState.GetVisitedNodeIds(usePreviousRoom);

            // If the node at which we entered is not allowed, this is not fulfilled.
            if (!NodeIds.Contains(visitedNodeIds.First()))
            {
                return(null);
            }

            // If we have visited a node to avoid, this is not fulfilled.
            if (NodeIdsToAvoid.Intersect(visitedNodeIds).Any())
            {
                return(null);
            }

            // If we were supposed to stay put but have visited more than the starting node, this is not fulfilled
            if (MustStayPut && visitedNodeIds.Count() > 1)
            {
                return(null);
            }

            // If we have destroyed an obstacle that needed to be preserved, this is not fulfilled
            if (ObstaclesIdsToAvoid.Intersect(inGameState.GetDestroyedObstacleIds(usePreviousRoom)).Any())
            {
                return(null);
            }

            // We've avoided all pitfalls. This ResetRoom is fulfilled. Clone the InGameState to fulfill method contract
            return(new ExecutionResult(inGameState.Clone()));
        }
        [U] public void Null()
        {
            NodeIds value = "foo";

            (value == null).Should().BeFalse();
            (null == value).Should().BeFalse();
        }
Esempio n. 3
0
        public StoryGraph(ISceneNode root, IReadOnlyList <Pair <int> > edges, bool sameLayout)
        {
            SameLayout = sameLayout;
            var aspectsUnsorted = root.GetComponent <IStoryComponent>().EnumerateStoryAspectsDeep(SameLayout).ToArray();
            var maxId           = aspectsUnsorted.Max(x => x.Node.Id);

            EnoughIntegers = Enumerable.Range(0, maxId + 1).ToArray();
            Aspects        = aspectsUnsorted.ToDictionary(x => x.Node.Id, x => x);
            NodeObjects    = aspectsUnsorted.ToDictionary(x => x.Node.Id, x => x.Node);
            NodeIds        = aspectsUnsorted.Select(x => x.Node.Id).ToArray();
            IsUsed         = EnoughIntegers.Select(x => NodeObjects.ContainsKey(x)).ToArray();
            Indices        = NodeObjects.ToDictionary(x => x.Value, x => x.Key);
            Children       = Aspects.ToDictionary(x => x.Key, x => (IReadOnlyList <int>)x.Value.EnumerateImmediateStoryChildren(SameLayout).Select(y => y.Node.Id).ToArray());
            Root           = root.Id;
            Parents        = NodeObjects.ToDictionary(x => x.Key, x => x.Value.ParentNode?.Id ?? -1);
            Depths         = NodeIds.ToDictionary(x => x, CalculateNodeDepth);
            Depth          = CalculateDepth(Root);
            Leaves         = EnumerateLeaves(Root).ToArray();
            NonLeaves      = EnumerateNonLeaves(Root).ToArray();
            BuildPrevNext(edges, out var next, out var previous, out var goodEdges);
            Next         = next;
            Previous     = previous;
            Neighbors    = Leaves.ToDictionary(x => x, x => (IReadOnlyList <int>)Next[x].Concat(Previous[x]).ToArray());
            Edges        = goodEdges;
            LeveledEdges = BuildLeveledEdges();
            BuildLeveledPrevNext(out var leveledNext, out var leveledPrev);
            LeveledNext         = leveledNext;
            LeveledPrevious     = leveledPrev;
            LeveledNeighbors    = NodeIds.ToDictionary(x => x, x => (IReadOnlyList <int>)LeveledNext[x].Concat(LeveledPrevious[x]).ToArray());
            ExternalConnections = BuildExternal();
            NodesInBfsOrder     = BreadthFirstSearch().ToArray();
        }
 public void changeSelectedNode(string newNodeId)
 {
     SelectedNodeId      = newNodeId;
     SelectedNodeAddress = NodeAddresses[NodeIds.FindIndex(x => x == newNodeId)];
     getSelectedNodeTempData();
     componentManager.updateNode();
 }
        [U] public void NotEq()
        {
            NodeIds types = "foo,bar";

            NodeIds[] notEqual = { "foo,bar,x", "foo" };
            foreach (var t in notEqual)
            {
                (t != types).ShouldBeTrue(t);
                t.Should().NotBe(types);
            }
        }
        [U] public void Eq()
        {
            NodeIds types = "foo,bar";

            NodeIds[] equal = { "foo,bar", "bar,foo", "foo,  bar", "bar,  foo   " };
            foreach (var t in equal)
            {
                (t == types).ShouldBeTrue(t);
                t.Should().Be(types);
            }
        }
Esempio n. 7
0
 private void BuildLeveledPrevNext(
     out IReadOnlyDictionary <int, IReadOnlyList <int> > next,
     out IReadOnlyDictionary <int, IReadOnlyList <int> > prev)
 {
     next = NodeIds.ToDictionary(x => x, x => (IReadOnlyList <int>) new List <int>());
     prev = NodeIds.ToDictionary(x => x, x => (IReadOnlyList <int>) new List <int>());
     foreach (var edge in Edges)
     {
         var leveledEdge = ToLeveledEdge(edge.First, edge.Second, out _);
         if (!next.TryGetValue(leveledEdge.First, out var firstList) ||
             !prev.TryGetValue(leveledEdge.Second, out var secondList))
         {
             throw new Exception("Fund an edge between unexisting node IDs.");
         }
         ((List <int>)firstList).AddUnique(leveledEdge.Second);
         ((List <int>)secondList).AddUnique(leveledEdge.First);
     }
 }
Esempio n. 8
0
        private IReadOnlyDictionary <int, IReadOnlyList <int> > BuildExternal()
        {
            var rExternal = NodeIds.ToDictionary(x => x, x => (IReadOnlyList <int>) new List <int>());

            foreach (var edge in Edges)
            {
                var commonParent = GetCommonParent(edge.First, edge.Second);

                var first = edge.First;
                while (Parents[first] != commonParent)
                {
                    ((List <int>)rExternal[first]).Add(edge.Second);
                    first = Parents[first];
                }

                var second = edge.Second;
                while (Parents[second] != commonParent)
                {
                    ((List <int>)rExternal[second]).Add(edge.First);
                    second = Parents[second];
                }
            }
            return(rExternal);
        }
        private void fetchNodeData()
        {
            //Database Stuff
            NpgsqlConnection conn = new NpgsqlConnection("Server=flick.cs.niu.edu;Port=5432;User Id=readonly;Database=aot;CommandTimeout=240");

            conn.Open();
            NpgsqlCommand command = new NpgsqlCommand("SELECT FORMAT('%s, %s', lat, lon) lat_lon, aot_node_id, address, start_timestamp, end_timestamp, lat, lon FROM aot_nodes WHERE project_id = 'AoT_Chicago' AND aot_node_id != '001e0610ef73';", conn);

            try
            {
                NpgsqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    NodeLocations.Add(reader.GetString(0));
                    NodeIds.Add(reader.GetString(1));
                    NodeAddresses.Add(reader.GetString(2));
                    NodeStart.Add(reader.GetTimeStamp(3).ToString());
                    try
                    {
                        NodeEnd.Add(reader.GetTimeStamp(4).ToString());
                    }
                    catch (System.InvalidCastException icex)
                    {
                        NodeEnd.Add("");
                    }
                    NodeLat.Add(reader.GetString(5));
                    NodeLon.Add(reader.GetString(6));
                }
            }
            catch (System.Exception ex)
            {
                print(ex.Message);
            }

            conn.Close();
        }
Esempio n. 10
0
            private async Task FindObjects(Opc.Ua.Client.Session session, NodeId nodeid)
            {
                if (session == null)
                {
                    return;
                }

                try
                {
                    ReferenceDescriptionCollection references;
                    Byte[] continuationPoint;

                    if (NodeIdsFromObjects.Contains(nodeid.ToString()))
                    {
                        return;
                    }

                    session.Browse(
                        null,
                        null,
                        nodeid,
                        0u,
                        BrowseDirection.Forward,
                        ReferenceTypeIds.HierarchicalReferences,
                        true,
                        (uint)NodeClass.Variable | (uint)NodeClass.Object,
                        out continuationPoint,
                        out references);

                    foreach (var rd in references)
                    {
                        Log(conn_name + " - " + rd.NodeId + ", " + rd.DisplayName + ", " + rd.BrowseName + ", " + rd.NodeClass);
                        if (rd.NodeClass == NodeClass.Variable && !NodeIds.Contains(rd.NodeId.ToString()))
                        {
                            NodeIds.Add(rd.NodeId.ToString());
                            ListMon.Add(
                                new MonitoredItem()
                            {
                                DisplayName      = rd.DisplayName.ToString(),
                                StartNodeId      = rd.NodeId.ToString(),
                                SamplingInterval = System.Convert.ToInt32(System.Convert.ToDouble(OPCUA_conn.autoCreateTagSamplingInterval) * 1000),
                                QueueSize        = System.Convert.ToUInt32(OPCUA_conn.autoCreateTagQueueSize),
                                MonitoringMode   = MonitoringMode.Reporting,
                                DiscardOldest    = true,
                                AttributeId      = Attributes.Value
                            });
                        }
                        else
                        if (rd.NodeClass == NodeClass.Object)
                        {
                            NodeIdsFromObjects.Add(nodeid.ToString());
                            await FindObjects(session, ExpandedNodeId.ToNodeId(rd.NodeId, session.NamespaceUris));

                            Thread.Yield();
                            //Thread.Sleep(1);
                            //await Task.Delay(1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log(conn_name + " - " + ex.Message);
                }
            }
        [U] public void NodeIds()
        {
            NodeIds fromString = "a,b,c,d";

            DebugFor(fromString).Should().Be("a,b,c,d");
        }