Exemple #1
0
        static Graph LoadBags(string input)
        {
            var graph = new Graph();

            foreach (var line in FileIterator.Lines(input))
            {
                var groups  = line.Groups("^(.+) bags contain (.+)\\.$");
                var bagType = groups[0];
                var bagNode = graph.GetOrCreate(bagType, () => (new(), new()));

                if (groups[1] != "no other bags")
                {
                    var children = groups[1].Split(',');
                    foreach (var child in children)
                    {
                        groups = child.Groups("(\\d+) (.+) bag");
                        bagNode.Item2.Add((int.Parse(groups[0]), groups[1]));

                        var childNode = graph.GetOrCreate(groups[1], () => (new(), new()));
                        childNode.Item1.Add(bagType);
                    }
                }
            }

            return(graph);
        }
Exemple #2
0
        public TechPyramid(int width, int height, int minDepth, int maxDepth, bool merges,
                           bool connections = true, bool lightTracer = true)
        {
            // Generate the filenames
            techniqueNames = new TechniqueNames();
            for (int depth = minDepth; depth <= maxDepth; ++depth)
            {
                // Hitting the light
                techniqueNames.Add(key: (cameraPathEdges: depth,
                                         lightPathEdges: 0,
                                         totalEdges: depth),
                                   value: $"{depth}-hit");

                if (depth == 1)
                {
                    continue;
                }

                // Light tracer
                if (lightTracer)
                {
                    techniqueNames.Add(key: (cameraPathEdges: 0,
                                             lightPathEdges: depth - 1,
                                             totalEdges: depth),
                                       value: $"{depth}-light-tracer");
                }

                // Next event estimation
                techniqueNames.Add(key: (cameraPathEdges: depth - 1,
                                         lightPathEdges: 0,
                                         totalEdges: depth),
                                   value: $"{depth}-next-event");

                // All connections
                for (int i = 1; i < depth - 1 && connections; ++i)
                {
                    techniqueNames.Add(key: (cameraPathEdges: i,
                                             lightPathEdges: depth - i - 1,
                                             totalEdges: depth),
                                       value: $"{depth}-connect-{i}");
                }

                // All merges
                for (int i = 1; i < depth && merges; ++i)
                {
                    techniqueNames.Add(key: (cameraPathEdges: i,
                                             lightPathEdges: depth - i,
                                             totalEdges: depth),
                                       value: $"{depth}-merge-{i}");
                }
            }

            // Create an image for every technique
            techniqueImages = new Dictionary <(int, int, int), RgbImage>();
            foreach (var tech in techniqueNames)
            {
                techniqueImages[tech.Key] = new RgbImage(width, height);
            }
        }
Exemple #3
0
        void CollectUp(Graph graph, string bagType, HashSet <string> visited)
        {
            var node = graph[bagType];

            foreach (var parent in node.Item1)
            {
                visited.Add(parent);
                CollectUp(graph, parent, visited);
            }
        }
Exemple #4
0
        private void Awake()
        {
            rules    = RuleInterpreter.Interpret();
            oneshots = new List <Rule>();

            worldMemory = new Dictionary <string, object>()
            {
                { "Time", Time.deltaTime }
            };
        }
Exemple #5
0
        private void HandleQuery(
            Query query,
            RuleMap rulesMap,
            List <Rule> oneshots)
        {
            if (!rulesMap.ContainsKey((query.Concept, query.Who)))
            {
                return;
            }

            var rules       = rulesMap[(query.Concept, query.Who)];
Exemple #6
0
        int CountDown(Graph graph, string bagType)
        {
            // Count the child bags exclusive of the container bag itself. That way, we only get a count of the bags
            // held within it. Callers must manually add 1 for the container bag itself if they care.
            var count = 0;

            var node = graph[bagType];

            foreach (var child in node.Item2)
            {
                count += child.Item1 + (child.Item1 * CountDown(graph, child.Item2));
            }

            return(count);
        }
Exemple #7
0
    private (ForwardCarry, HashSet <string>) DoGrammar(IShape shape, NodeMap nodePlacement)
    {
        // Control grammar
        if (shape.Control.Count != 0)
        {
            HashSet <ControlAssignment> attributeOverwrite = new HashSet <ControlAssignment>();
            foreach (string control in shape.Control)
            {
                attributeOverwrite.UnionWith(cg.Interpret(control));
            }

            return(this.Assign(attributeOverwrite, nodePlacement));
        }

        return(new ForwardCarry(), new HashSet <string>());
    }
Exemple #8
0
        public DesiredShape ForLoop()
        {
            var answer = new DesiredShape();

            foreach (var n in Words)
            {
                if (n.Length >= 3)
                {
                    var key = (n[0], n[1], n[2]);
                    if (!answer.TryGetValue(key, out var words))
                    {
                        words       = new List <string>();
                        answer[key] = words;
                    }
                    words.Add(n);
                }
            }

            return(answer);
        }
Exemple #9
0
        public static RuleMap Interpret()
        {
            var ruleMap    = new RuleMap();
            var toOrganize = new List <List <Rule> >();

            using (var reader = new StreamReader(Application.dataPath + "/Resources/Dialogue/csvtest.csv"))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    var fixtures = csv.GetRecords <RuleFixture>();

                    foreach (var fixture in fixtures)
                    {
                        var id       = fixture.Id;
                        var criteria = ParseCriteriaCodes(id, fixture.Criteria);
                        var remember = ParseRemembererCodes(id, fixture.Remember);

                        var ruleKey = (fixture.Concept, fixture.Who);
                        if (!ruleMap.ContainsKey(ruleKey))
                        {
                            ruleMap[ruleKey] = new List <Rule>();
                            toOrganize.Add(ruleMap[ruleKey]);
                        }

                        ruleMap[ruleKey].Add(new Rule(
                                                 id,
                                                 criteria,
                                                 remember,
                                                 fixture.Response,
                                                 fixture.Cooldown));
                    }
                }

            // Sort each collection of rules in decending number of criteria,
            // i.e. We want to take more specific rules first.
            foreach (var l in toOrganize)
            {
                l.Sort((x, y) => y.NumCriteria.CompareTo(x.NumCriteria));
            }

            return(ruleMap);
        }
        private static Proababilities CalculateSeqProbabilities(IEnumerable <ISymbol> population)
        {
            var cumulativeProbability = 0.0m;
            var correctionCoeficient  = population.Sum(p => p.Probability) != 1.0m
                                            ? 1.0m / population.Sum(p => p.Probability)
                                            : 1.0m;

            var seqProbabilities = new Proababilities();

            foreach (var entity in population)
            {
                var adjustedProabability = entity.Probability * correctionCoeficient;
                seqProbabilities.Add(entity, (cumulativeProbability, cumulativeProbability + adjustedProabability));
                cumulativeProbability += adjustedProabability;
            }

            if (cumulativeProbability != 1.0m)
            {
                throw new Exception("Symbols probabilities sum must be exactly 100%.");
            }

            return(seqProbabilities);
        }
Exemple #11
0
 private DefinitionsContainer(DefinitionsIndex index)
 {
     definitions = index;
 }
 public SpawnItemService(Pool pool)
 {
     Pool = pool;
 }
Exemple #13
0
    private (ForwardCarry, HashSet <string>) Assign(ICollection <ControlAssignment> assignments, NodeMap nodePlacement)
    {
        ForwardCarry     forwardCarry      = new ForwardCarry();
        HashSet <string> activationSymbols = new HashSet <string>();
        HashSet <((uint, uint), string)> handledLocators = new HashSet <((uint, uint), string)>();

        // Console.WriteLine("Control");
        foreach (ControlAssignment ca in assignments)
        {
            // Get all the locators meant by the locator
            List <(uint, uint)> reqLocators = new List <(uint, uint)>();
            foreach ((uint x, uint y)all in nodePlacement.Keys)
            {
                if ((ca.Loc.x == all.x || ca.Loc.x == ~0u) && (ca.Loc.y == all.y || ca.Loc.y == ~0u))
                {
                    if (ca.Loc.x == all.x && ca.Loc.y == all.y)
                    {
                        reqLocators.Add(all);
                    }

                    else if (!handledLocators.Contains((all, ca.Attr)))
                    {
                        reqLocators.Add(all);
                    }

                    handledLocators.Add((all, ca.Attr));
                }
            }

            foreach ((uint x, uint y)all in reqLocators)
            {
                ShapeGraph.Node node = nodePlacement[all][0];

                // If the assignment is nonterminal, it will be used by
                // some following steps in the control pipeline
                if (!ca.IsTerminal)
                {
                    // If the assignment evokes WFC
                    if (this.activationSymbols.Contains(ca.Attr))
                    {
                        activationSymbols.Add(ca.Attr);
                    }

                    // If the assignment sets a WFC constraint
                    else
                    {
                        if (!forwardCarry.ContainsKey(node))
                        {
                            forwardCarry.Add(node, new HashSet <string>());
                        }

                        forwardCarry[node].Add(ca.Next);
                    }
                }

                else
                {
                    foreach (ShapeGraph.Node n in nodePlacement[all])
                    {
                        // Set the attribute
                        if (ca.Attr != "")
                        {
                            n.Shape.Attributes.Set(ca.Attr, new ScalarAttribute(ca.Value));
                        }

                        // Add the control symbol
                        if (ca.Next != "")
                        {
                            n.Shape.Control.Add(ca.Next);
                        }
                    }
                }
            }
        }

        return(forwardCarry, activationSymbols);
    }
 public SymbolRandomizer(ICollection <ISymbol> population)
 {
     _seqProbabilities = CalculateSeqProbabilities(population);
 }