Example #1
0
        public void VerifyPartialRandomInvalidWords()
        {
            SuffixTree tree = new SuffixTree(theString);
            tree.BuildTree();

            Random random = new Random((int)DateTime.Now.Ticks);
            foreach (string individualString in individualStrings)
            {
                StringBuilder builder = new StringBuilder(individualString);
                //this will inject random characters into valid words
                for (int j = random.Next(individualString.Length-2); j < random.Next(individualString.Length); j++)
                {
                    builder.Insert(j,random.Next('a', 'z'));
                }
                string builtString = builder.ToString();
                string message = "Corrupting: " + individualString + " as " + builtString;
                //I originally checked to see if builder is in individualStrings, however with such a large
                //data set it took way too long to execute. There is a risk that a random string of 5 to 15
                //characters IS in the word list!
                if (!individualStrings.Contains(builtString))
                {
                    Assert.IsTrue(!tree.Search(builtString), message);
                }
            }
        }
Example #2
0
 public static void Save(Stream stream, SuffixTree tree)
 {
     using (BinaryWriter writer = new BinaryWriter(stream))
     {
         Save(writer, tree);
     }
 }
Example #3
0
        private static void Main(string[] args)
        {
            Console.Write("Enter a string: ");
             string something = Console.ReadLine();
             string[] tokens = something.Split();
             int[] numbers = Array.ConvertAll(tokens, int.Parse);
             List<int> numberList = new List<int>(numbers);
             SuffixTree tree = new SuffixTree(numberList);
             tree.BuildTree();

             while (true)
             {
            Console.Write("Search for: ");

            string searchTerm = Console.ReadLine();
            tokens = something.Split();
            numbers = Array.ConvertAll(tokens, int.Parse);
            numberList = new List<int>(numbers);

            if (tree.Search(numberList))
            {
               Console.WriteLine("It's in there!");
            }
            else
            {
               Console.WriteLine("Nope not in there!");
            }
            if (searchTerm.ToLower() == "quit")
            {
               break;
            }
             }
        }
Example #4
0
 public static void Save(Stream stream, SuffixTree tree)
 {
     using (BinaryWriter writer = new BinaryWriter(stream))
     {
         Save(writer, tree);
     }
 }
Example #5
0
        static void Main(string[] args)
        {
            Console.Write("Enter a string: ");
            string something = Console.ReadLine();
            SuffixTree tree = new SuffixTree(something);
            tree.BuildTree();

            while (true)
            {
                Console.Write("Search for: ");
                string searchTerm = Console.ReadLine();
                if (tree.Search(searchTerm))
                {
                    Console.WriteLine("It's in there!");
                }
                else
                {
                    Console.WriteLine("Nope not in there!");
                }
                if (searchTerm.ToLower() == "quit")
                {
                    break;
                }
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            Console.Write("Enter a string: ");
            string     something = Console.ReadLine();
            SuffixTree tree      = new SuffixTree(something);

            tree.BuildTree();

            while (true)
            {
                Console.Write("Search for: ");
                string searchTerm = Console.ReadLine();
                if (tree.Search(searchTerm))
                {
                    Console.WriteLine("It's in there!");
                }
                else
                {
                    Console.WriteLine("Nope not in there!");
                }
                if (searchTerm.ToLower() == "quit")
                {
                    break;
                }
            }
        }
Example #7
0
 public static void Save(BinaryWriter writer, SuffixTree tree)
 {
     writer.Write(SuffixTree.Edges.Count);
     writer.Write(SuffixTree.theString.Length);
     writer.Write(SuffixTree.theString);
     foreach (KeyValuePair<int, Edge> edgePair in SuffixTree.Edges)
     {
         writer.Write(edgePair.Key);
         writer.Write(edgePair.Value.endNode);
         writer.Write(edgePair.Value.startNode);
         writer.Write(edgePair.Value.indexOfFirstCharacter);
         writer.Write(edgePair.Value.indexOfLastCharacter);
     }
 }
Example #8
0
 public static void Save(BinaryWriter writer, SuffixTree tree)
 {
     writer.Write(SuffixTree.Edges.Count);
     writer.Write(SuffixTree.theString.Length);
     writer.Write(SuffixTree.theString);
     foreach (KeyValuePair <int, Edge> edgePair in SuffixTree.Edges)
     {
         writer.Write(edgePair.Key);
         writer.Write(edgePair.Value.endNode);
         writer.Write(edgePair.Value.startNode);
         writer.Write(edgePair.Value.indexOfFirstCharacter);
         writer.Write(edgePair.Value.indexOfLastCharacter);
     }
 }
Example #9
0
 public void VerifyValidWords()
 {
     int count = 0;
     SuffixTree tree = new SuffixTree(theString);
     tree.BuildTree();
     Stopwatch timer = Stopwatch.StartNew();
     
     foreach (string individualString in individualStrings)
     {
         Assert.IsTrue(tree.Search(individualString));
         count++;
     }
     timer.Stop();
     Console.WriteLine(count + " words processed in " + timer.ElapsedMilliseconds + " miliseconds.");
 }
Example #10
0
        public static string LongestPalindromicWithSuffixTree(string s)
        {
            var n = s.Length;

            if (n == 0)
            {
                return("");
            }
            SuffixTree sTree = new SuffixTree(s);

            sTree.Create();
            for (var i = 0; i < n - 1; i++)
            {
            }
            return("");
        }
Example #11
0
 public static SuffixTree LoadFromFile(BinaryReader reader)
 {
     SuffixTree tree;
     int count = reader.ReadInt32();
     int theStringLength = reader.ReadInt32();
     string theString = reader.ReadString();
     tree = new SuffixTree(theString);
     for (int i = 0; i < count; i++)
     {
         int key = reader.ReadInt32();
         Edge readEdge = new Edge(-1);
         readEdge.endNode = reader.ReadInt32();
         readEdge.startNode = reader.ReadInt32();
         readEdge.indexOfFirstCharacter = reader.ReadInt32();
         readEdge.indexOfLastCharacter = reader.ReadInt32();
         SuffixTree.Edges.Add(key, readEdge);
     }
     return tree;
 }
Example #12
0
        public void VerifyValidWordsFromFile()
        {
            SuffixTree tree = new SuffixTree(theString);
            tree.BuildTree();
            using (FileStream writeFile = new FileStream("suffixtreetest", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                SuffixTree.Save(writeFile, tree);
            }

            SuffixTree testTree;

            using (FileStream readFile = new FileStream("suffixtreetest", FileMode.Open, FileAccess.Read, FileShare.None))
            {
                testTree = SuffixTree.LoadFromFile(readFile);
            }
            foreach (string individualString in individualStrings)
            {
                Assert.IsTrue(testTree.Search(individualString));
            }
        }
Example #13
0
        public static SuffixTree LoadFromFile(BinaryReader reader)
        {
            SuffixTree tree;
            int        count           = reader.ReadInt32();
            int        theStringLength = reader.ReadInt32();
            string     theString       = reader.ReadString();

            tree = new SuffixTree(theString);
            for (int i = 0; i < count; i++)
            {
                int  key      = reader.ReadInt32();
                Edge readEdge = new Edge(-1);
                readEdge.endNode               = reader.ReadInt32();
                readEdge.startNode             = reader.ReadInt32();
                readEdge.indexOfFirstCharacter = reader.ReadInt32();
                readEdge.indexOfLastCharacter  = reader.ReadInt32();
                SuffixTree.Edges.Add(key, readEdge);
            }
            return(tree);
        }
Example #14
0
        public void VerifyRandomInvalidWords()
        {
            SuffixTree tree = new SuffixTree(theString);
            tree.BuildTree();

            Random random = new Random((int)DateTime.Now.Ticks);

            for (int i = 0; i < individualStrings.Count; i++)
            {
                StringBuilder builder = new StringBuilder();
                for (int j = 5; j < random.Next(15); j++)
                {
                    builder.Append(random.Next('a', 'z'));
                }
                string builtString = builder.ToString();
                string message = "Random String " + builtString + " was found!";

                //I originally checked to see if builder is in individualStrings, however with such a large
                //data set it took way too long to execute. There is a risk that a random string of 5 to 15
                //characters IS in the word list!
                Assert.IsTrue(!tree.Search(builtString));
            }
        }
Example #15
0
 public void VerifyValidWords()
 {
     SuffixTree tree = new SuffixTree(theString);
     tree.BuildTree();
     foreach (string individualString in individualStrings)
     {
         Assert.IsTrue(tree.Search(individualString));
     }
 }
Example #16
0
        void Load()
        {
            //shader1337 = new _1337Shader(this);

            normalGameplayRenderer = new GridScreenRenderer(this);
            recentWords = new RecentWordsRenderer(this, 5);
            letterSet = new ScrabbleSet();
            goalRenderer = new GoalRenderer(this);
            gameplayTimer = new TimerComponent(this);
            timerRenderer = new TimerRenderer(this);
            freeSpellMode = new FreeSpellMode(this);
            creditsBackground = new CreditsBackground(this);
            creditsForeground = new CreditsForeground(this);

            Grid grid = new Grid(alphabet);
            letterSet.Alphabet = alphabet;
            Shorewood.wordDatabase = Content.Load<SuffixTree>("Words\\2of4brif");

            grid.wordDatabase = Shorewood.wordDatabase;

            grid.letterSet = letterSet;
            float gridActualWidth = 450;//(grid.width * alphabet['z'].texture.Width + alphabet['z'].texture.Width / 2) * scale;
            float gridActualHeight = (grid.height * alphabet['z'].texture.Height * 2 / 3) * scale;

            normalGameplayRenderer.grid = grid;
            normalModeGamePlay = new NormalGameplay(this, PlayerIndex.One, alphabet, normalGameplayRenderer, letterSet);
            gameplayTimer.AddEvent(new TimeSpan(), new OnTime(normalModeGamePlay.GameOver));
            normalModeGamePlay.wordAnimationRenderer = foundWordAnimator;
            normalGameplayRenderer.Enabled = false;

            foundWordAnimator.scale = scale;
            foundWordAnimator.destination = new Vector2(titleSafeArea.X + 20, titleSafeArea.Y + 60);
            foundWordAnimator.destinationScale = 0.5f;
            foundWordAnimator.recentWords = recentWords;

            normalGameplayRenderer.foundWordAnimator = foundWordAnimator;
            normalGameplayRenderer.scale = scale;
            normalGameplayRenderer.position = new Vector2(titleSafeArea.Width / 2 - gridActualWidth / 2 + titleSafeArea.X, titleSafeArea.Y);
            normalGameplayRenderer.Visible = false;

            goalRenderer.position = new Vector2(normalGameplayRenderer.position.X + gridActualWidth + 10, titleSafeArea.Y + 20);

            foundWordAnimator.startPositionOffset = normalGameplayRenderer.position;

            recentWords.position = foundWordAnimator.destination;
            recentWords.startOffsetPosition = foundWordAnimator.startPositionOffset;
            recentWords.scale = scale;

            normalModeGamePlay.Enabled = false;

            isLoaded = true;

            Components.Add(constantBackground);

            Components.Add(normalModeGamePlay);
            Components.Add(normalGameplayRenderer);
            Components.Add(goalRenderer);

            Components.Add(recentWords);

            Components.Add(scoreBox);

            Components.Add(foundWordAnimator);
            Components.Add(timerRenderer);
            Components.Add(freeSpellMode);
            bloom.Settings = BloomSettings.PresetSettings[(int)BloomType.Blurry];
            Components.Add(bloom);
            Components.Add(creditsBackground);
            Components.Add(particleSystem);
            Components.Add(creditsForeground);
            Components.Add(menu);
            Components.Add(dialogManager);
            Components.Add(popUpManager);
            Components.Add(storageScreen);
            Components.Add(gameplayTimer);

            bloom.Enabled = false;
            bloom.Visible = false;
            levelManager = new NormalGameplayLevelManager();
            normalModeGamePlay.levelManager = levelManager;
            goalRenderer.levelManager = levelManager;

            GC.Collect();
            soundTrack.Start();
        }