Beispiel #1
0
        //Method to generate the book
        public string generateBook(BookStruct bookS, bool highlight)
        {
            //So here we extract the information from the BookStruct object
            IntX seed = convertFromBase(bookS.searchText, bases);

            //We make a seed based on the location and page
            int    seed2 = (int)(bookS.wall * bookS.shelf * bookS.vol * bookS.page * (seed % 10));
            Random r     = new Random(seed2); //And set this random to use this seed

            //Let's make a new array for the one page. We know each page is 3200 chars long beforehand
            char[] page = new char[3200];
            bool   flag = false;

            for (int i = 0; i < 3200;)
            {
                if ((i == bookS.expectedLoc) && (bookS.page == bookS.expectedPage))
                {
                    flag = true; //Here, we raise the flag, saying that the page and location needs the user search text!
                }
                if (flag)
                {
                    if ((i - bookS.expectedLoc) >= bookS.searchText.Length)
                    {
                        flag = false;
                    }
                    else
                    {
                        //So, we be all sneaky and replace the randomly generated text with the user search text
                        page[i] = bookS.searchText[i - (int)bookS.expectedLoc];
                        if (highlight)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                        }
                        Console.Write(page[i]);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                }
                else
                {
                    //Generate random text from our alphabet
                    page[i] = bases[r.Next(bases.Length)];
                    Console.Write(page[i]);
                }
                i++;
            }

            return(new string(page)); //And return the page
        }
Beispiel #2
0
        //We decode and extract the information from the hexagon address
        public BookStruct decodeHex(string hex)
        {
            string text; //The original user search string

            //We first test the last character if its one,
            //Then it's compressed. Else, its not
            if (hex[hex.Length - 1] == '1')
            {
                text = hex.Substring(0, hex.Length - 1);                     //Trim the ending
                text = Compressor.Unzip(Compressor.StringToByteArray(text)); //Convert hex into byte array into decompressed text
            }
            else
            {
                text = hex.Substring(0, hex.Length - 1);
                text = convertToBase(convertFromBase(text, hexes).ToString(), bases); //Revert back to original state
            }

            IntX seed = convertFromBase(text, bases); //Seed we used in the encode hex method

            RNG.setSeeds(seed, seed % answerToLifeTheUniverseAndEverything);

            //Because the seed is the same, and unique per user-input, we can
            //expect the same wall, shelf and volume to be outputted as when we
            //generated the values
            IntX   e_wall  = RNG.getRRandom(1, 4);
            IntX   e_shelf = RNG.getRRandom(1, 5);
            IntX   e_vol   = RNG.getRRandom(1, 32);
            Random r       = new Random((int)RNG.getRand());

            //We generated this in the encodehex but here we generate it again
            //and due to the seed being the same, we should get the same results
            int loc       = r.Next(1, 410);
            int locOnPage = r.Next(3200);

            //Dump all those information into an object
            BookStruct ret = new BookStruct(e_wall, e_shelf, e_vol, loc, hex)
            {
                expectedLoc  = locOnPage,
                searchText   = text,
                expectedPage = loc
            };

            return(ret);
        }