Example #1
0
        public void Interface()
        {
            ICollection <int> c = new CircularQueue <int>(20);

            Assert.IsFalse(c.Remove(5));

            c.Add(2);

            Assert.AreEqual(c.Count, 1);
            Assert.IsTrue(c.Remove(2));
            Assert.AreEqual(c.Count, 0);

            c.Add(4);
            c.Add(5);
            c.Add(6);

            Assert.AreEqual(c.Count, 3);
            Assert.IsFalse(c.Remove(2));
            Assert.AreEqual(c.Count, 3);

            Assert.IsTrue(c.Remove(5));
            Assert.AreEqual(c.Count, 2);

            Assert.IsTrue(c.Remove(6));
            Assert.AreEqual(c.Count, 1);

            Assert.IsTrue(c.Remove(4));
            Assert.AreEqual(c.Count, 0);
        }
Example #2
0
        public void Interface()
        {
            ICollection<int> c = new CircularQueue<int>(20);
            Assert.IsFalse(c.Remove(5));

            c.Add(2);

            Assert.AreEqual(c.Count, 1);
            Assert.IsTrue(c.Remove(2));
            Assert.AreEqual(c.Count, 0);

            c.Add(4);
            c.Add(5);
            c.Add(6);

            Assert.AreEqual(c.Count, 3);
            Assert.IsFalse(c.Remove(2));
            Assert.AreEqual(c.Count, 3);

            Assert.IsTrue(c.Remove(5));
            Assert.AreEqual(c.Count, 2);

            Assert.IsTrue(c.Remove(6));
            Assert.AreEqual(c.Count, 1);

            Assert.IsTrue(c.Remove(4));
            Assert.AreEqual(c.Count, 0);
        }
Example #3
0
    public IEnumerator TearDownRamp()
    {
        while (pathQueue.Peek() != null)
        {
            GameObject pathObj = pathQueue.Add(null).gameObject;
            Destroy(pathObj);
            yield return(new WaitForSeconds(tearDownTime));
        }

        tearDownComplete = true;
    }
Example #4
0
        public double SequenceProbability(string[] inData)
        {
            CircularQueue <string> queue = new CircularQueue <string>(n - 1);
            double logProbabilitySum     = 0;

            foreach (string token in inData)
            {
                if (queue.IsFull())
                {
                    string key = string.Join(",", queue.ToArray());
                    if (grammar.ContainsKey(key))
                    {
                        Dictionary <string, float> keyToProbability = grammar[key].GetValues(null);

                        if (keyToProbability.ContainsKey(token))
                        {
                            logProbabilitySum += Math.Log(keyToProbability[token]);
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else
                    {
                        return(0);
                    }
                }

                queue.Add(token);
            }

            return(Math.Pow(Math.E, logProbabilitySum));
        }
Example #5
0
    /// <summary>
    /// Adds a delay to the sequence.
    /// </summary>
    /// <param name="delay">The delay in seconds.</param>
    public ChainSequence AddDelay(float delay)
    {
        times.Add(delay);
        Action action = StartDelay;
        var    step   = new ChainStep(ChainStepType.DELAY, action);

        steps.Add(step);
        return(this);
    }
Example #6
0
        public void CanAdd_Test()
        {
            CircularQueue <string> queue = new CircularQueue <string>(5);

            queue.Add("First");
            queue.Add("Second");
            queue.Add("Third");
            queue.Add("Fourth");
            queue.Add("Fifth");

            Assert.IsTrue(queue[0] == "First");
            Assert.IsTrue(queue[1] == "Second");
            Assert.IsTrue(queue[2] == "Third");
            Assert.IsTrue(queue[3] == "Fourth");
            Assert.IsTrue(queue[4] == "Fifth");

            Assert.IsTrue(queue.Head == 0);
            Assert.IsTrue(queue.Tail == 4);
        }
Example #7
0
        public void Start()
        {
            runningThreads = new List <Tuple <Thread, System.Diagnostics.Stopwatch> >();

            if (Directory.Exists(basePath) == false)
            {
                Directory.CreateDirectory(basePath);
            }

            List <Thread> threads = new List <Thread>();

            threads.AddRange(Run("GameFlow/PCGPlatformer", "custom", Games.Custom));
            threads.AddRange(Run("GameFlow/SuperMarioBros", "smb", Games.SuperMarioBros));
            threads.AddRange(Run("GameFlow/SuperMarioBros2", "smb2", Games.SuperMarioBros2));
            threads.AddRange(Run("GameFlow/SuperMarioBros2Japan", "smb2j", Games.SuperMarioBros2Japan));
            threads.AddRange(Run("GameFlow/SuperMarioLand", "sml", Games.SuperMarioLand));

            totalThreads = threads.Count;
            this.threads = new Stack <Thread>(threads);

            threadCount = Environment.ProcessorCount - 1;

            relevantText.Add($"{numSimulations} simulations per a thread.");
            relevantText.Add("Threads built. Starting Process.");
        }
Example #8
0
        private static List <string> GenerateTree(
            ICompiledGram gram,
            CircularQueue <string> prior,
            int size,
            int index,
            List <string> acceptedTypes,
            Func <string, string> classifier)
        {
            string[] guesses = gram.GetGuesses(prior.ToArray());
            foreach (string guess in guesses)
            {
                if (classifier != null &&
                    !classifier(guess).Equals(acceptedTypes[index]))
                {
                    continue;
                }

                CircularQueue <string> newPrior = prior.Clone();
                newPrior.Add(guess);

                if (size <= 1)
                {
                    return(new List <string>()
                    {
                        guess
                    });
                }
                else if (gram.HasNextStep(newPrior.ToArray()))
                {
                    List <string> returnVal = GenerateTree(
                        gram,
                        newPrior,
                        size - 1,
                        index + 1,
                        acceptedTypes,
                        classifier);

                    if (returnVal != null)
                    {
                        returnVal.Insert(0, guess);
                        return(returnVal);
                    }
                }
            }

            return(null);
        }
Example #9
0
    public void SetupRamp(GameObject rampObject)
    {
        pathQueue = new CircularQueue <PathPrefab>(queueLength);
        buildPoint.transform.position = new Vector3(0, 0, 30);
        tearDownComplete = false;
        foreach (Transform child in rampObject.transform)
        {
            ramp = child.gameObject;
            ramp.GetComponent <BoxCollider>().enabled = false;
            pathQueue.Add(ramp.GetComponent <PathPrefab>());
        }

        lastDirection = Direction.North;
        lastPath      = ramp.GetComponent <PathPrefab>();

        mazePathA      = MazeCreator.FindPath(mazeDim, mazeDim, lastDirection);
        choosePathA    = true;
        mazePathIndex  = 0;
        mazePathBuffer = 10;
    }
Example #10
0
        // @NOTE: this is used for simulation. Do not use outside of it.
        public static List <string> GenerateBestAttempt(
            ICompiledGram gram,
            List <string> start,
            int size,
            int maxAttempts)
        {
            List <string> best = null;

            for (int i = 0; i < maxAttempts; ++i)
            {
                CircularQueue <string> prior = new CircularQueue <string>(gram.GetN() - 1);
                prior.AddRange(start);

                List <string> output = new List <string>();
                while (size > 0 && gram.HasNextStep(prior.ToArray()))
                {
                    string nextToken = gram.Get(prior.ToArray());
                    output.Add(nextToken);
                    prior.Add(nextToken);
                    --size;
                }

                if (size == 0)
                {
                    best = output;
                    break;
                }

                if (best == null)
                {
                    best = output;
                }
                else if (output.Count > best.Count)
                {
                    best = output;
                }
            }

            return(best);
        }
Example #11
0
        public double SequenceProbability(string[] inData)
        {
            CircularQueue <string>     buffer = new CircularQueue <string>(n - 1);
            Dictionary <string, float> temp;
            double probabilitySum = 0;

            foreach (string token in inData)
            {
                temp = GetCompiledUniGram(buffer.ToArray(), buffer.Count + 1).GetValues(null);
                if (temp.ContainsKey(token))
                {
                    probabilitySum += Math.Log(temp[token]);
                }
                else
                {
                    return(0);
                }

                buffer.Add(token);
            }

            return(Math.Pow(Math.E, probabilitySum));
        }
Example #12
0
 public void AddInput(Input input)
 {
     buffer.Add(input);
 }
Example #13
0
        public void CanAddToLoopAround_Test()
        {
            CircularQueue <string> queue = new CircularQueue <string>(5);

            queue.Add("First");
            queue.Add("Second");
            queue.Add("Third");
            queue.Add("Fourth");
            queue.Add("Fifth");
            queue.Add("Sixth");
            queue.Add("Seventh");
            queue.Add("Eighth");
            queue.Add("Ninth");
            queue.Add("Tenth");
            queue.Add("Eleventh");

            Assert.IsTrue(queue[0] == "Eleventh");
            Assert.IsTrue(queue[1] == "Seventh");
            Assert.IsTrue(queue[2] == "Eighth");
            Assert.IsTrue(queue[3] == "Ninth");
            Assert.IsTrue(queue[4] == "Tenth");

            Assert.IsTrue(queue.Head == 1);
            Assert.IsTrue(queue.Tail == 0);
        }
Example #14
0
        // @NOTE: this is used for simulation. Do not use outside of it.
        public static List <string> GenerateBestRestrictedAttempt(
            ICompiledGram gram,
            List <string> start,
            List <string> acceptedTypes,
            Func <string, string> classifier,
            int maxAttempts)
        {
            List <string> best = null;

            for (int attempt = 0; attempt < maxAttempts; ++attempt)
            {
                CircularQueue <string> prior = new CircularQueue <string>(gram.GetN() - 1);
                prior.AddRange(start);

                int           acceptedTypeIndex = 0;
                List <string> output            = new List <string>();
                string        token;
                int           i;

                while (acceptedTypeIndex < acceptedTypes.Count && gram.HasNextStep(prior.ToArray()))
                {
                    string[] tokens    = gram.GetGuesses(prior.ToArray());
                    string   nextToken = null;

                    string acceptedType = acceptedTypes[acceptedTypeIndex];
                    for (i = 0; i < tokens.Length; ++i)
                    {
                        token = tokens[i];
                        if (classifier.Invoke(token).Equals(acceptedType))
                        {
                            nextToken = token;
                        }
                    }

                    if (nextToken != null)
                    {
                        output.Add(nextToken);
                        prior.Add(nextToken);
                        acceptedTypeIndex += 1;
                    }
                    else
                    {
                        break;
                    }
                }

                if (output.Count == acceptedTypes.Count)
                {
                    best = output;
                    break;
                }

                if (best == null)
                {
                    best = output;
                }
                else if (output.Count > best.Count)
                {
                    best = output;
                }
            }

            return(best);
        }