예제 #1
0
    /// <summary>
    /// Returns list of Interactable IDs generated from encoding a seed string into
    /// a series of interactable actions.
    /// </summary>
    private InteractableID[] getPathIDs(string seedString)
    {
        // This is specifically for 108 bit seeds used in the devcon demo
        List <int> bitList = SeedToByte.customList(3, 4, 2, 4, 4);

        int[] actions = converter.getActions(seedString, bitList);

        List <InteractableID> locationIDs = new List <InteractableID>();

        int count = 0;

        while (count < actions.Length)
        {
            int siteID = actions[count];

            for (int j = 0; j < SeedManager.ActionCount; j++)
            {
                int spotID   = actions[count + (2 * j) + 1];
                int actionID = actions[count + (2 * j) + 2];
                locationIDs.Add(new InteractableID(siteID, spotID, actionID));
            }

            count += 1 + 2 * SeedManager.ActionCount;
        }

        return(locationIDs.ToArray());
    }
예제 #2
0
    /// <summary>
    /// Encodes an list of interactables into a seed string
    /// </summary>
    public string InteractableListToSeed(Interactable[] list)
    {
        if (list.Length == 0)
        {
            return("");
        }

        int        totalInt  = (2 * SeedManager.ActionCount) + SeedManager.SiteCount;
        int        counter   = 0;
        List <int> actionLog = new List <int>();

        for (int j = 0; j < SeedManager.SiteCount; j++)
        {
            actionLog.Add(list[(counter)].ID.siteID);
            for (int i = 0; i < SeedManager.ActionCount; i++)
            {
                actionLog.Add(list[counter].ID.spotID);
                actionLog.Add(list[counter].ID.actionID);
                counter += 1;
            }
        }

        int[] actionArray = actionLog.ToArray();

        List <int> bitList = SeedToByte.customList(3, 4, 2, 4, 4);

        return(converter.getSeed(actionArray, bitList));
    }
예제 #3
0
    /// <summary>
    /// Returns recovered seed which as been decodes from a list of interactions
    /// </summary>
    public string DecodeSeed(InteractableLog log)
    {
        int[]      encodedInteractions = EncodeInteractions(log);
        List <int> bitList             = SeedToByte.customList(3, 4, 2, 4, 4);

        return(converter.getSeed(encodedInteractions, bitList));
    }
예제 #4
0
    // Modified to create a list of gameobjects with interactable attached as monobehavior
    private Interactable[] GetInteractableLocations()
    {
        SeedToByte locations = NavAIMesh.GetComponent <SeedToByte>();

        int[] actions = locations.getActions(gameState.SeedString);
        List <Interactable> locationIDs = new List <Interactable>();

        int count = 0;

        while (count < actions.Length)
        {
            int siteID = actions[count];

            for (int j = 0; j < gameState.ActionCount; j++)
            {
                int spotID   = actions[count + (2 * j) + 1];
                int actionID = actions[count + (2 * j) + 2];
                locationIDs.Add(new Interactable(siteID, spotID, actionID));
            }

            count += 1 + 2 * gameState.ActionCount;
        }

        return(locationIDs.ToArray());
    }
예제 #5
0
    public void getSeedFromDataCustom()
    {
        int[] playerChoices = new int[24];

        // using a custom list:
        List <int> customBitValues = SeedToByte.customList(2, 3, 2, 2, 2);
        string     seed            = seedToByte.getSeed(playerChoices, customBitValues);

        //Debug.Log("Seed: " + seed);
    }
예제 #6
0
    // To use different bit values, either use another list or make one using customList()
    public void getDataFromSeedCustom()
    {
        string seed = "FFFFFF"; // seed must be in hexidecimal

        int siteBits        = 2;
        int spotBits        = 3;
        int actionBits      = 2;
        int numberOfActions = 2;
        int numberOfSites   = 2;

        List <int> customBitValues = SeedToByte.customList(siteBits, spotBits, actionBits, numberOfActions, numberOfSites);

        int[] interactableData = seedToByte.getActions(seed, customBitValues);
    }
예제 #7
0
    public void runLeadingBits(ref int[] passed, int leadingBit, int totalBit, int value,
                               int expected1, int expected2, int expected3, int testNumber)
    {
        passed[1] += 1;
        int[] leadingBits = new int[3];

        leadingBits = SeedToByte.findLeadingBitValue(leadingBit, totalBit, value);

        if (leadingBits[0] == expected1 && leadingBits[1] == expected2 && leadingBits[2] == expected3)
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Leading bits test " + testNumber + " failed");
        }
    }
예제 #8
0
    // test seed converter for all possible seed sizes
    //  Creates a byte array filled with maximum possible values for N bits, and
    //  converts to an action list and back with seedConverterUniversal()
    public int[] testAllSizeSeeds()
    {
        int[] passed = new int[2];

        for (int i = 10; i < 129; i++)
        {
            List <int> hexList = new List <int>();
            for (int j = 0; j < i; j++)
            {
                hexList.Add(1);
            }

            byte[] byteHex = new byte[(i / 8) + 1];

            if (i % 8 == 0)
            {
                byteHex = new byte[i / 8];
            }

            for (int j = 0; j < byteHex.Length; j++)
            {
                byteHex[j] = 255;
            }

            byteHex[byteHex.Length - 1] = (byte)(Math.Pow(2, i % 8) - 1);

            BitArray hexBits    = seedToByte.byteToBits(byteHex);
            int[]    hexActions = seedToByte.bitToActions(hexBits, hexList);
            byte[]   finalSeed  = SeedToByte.seedConverterUniversal(hexActions, hexList);

            passed[1] += 1;

            if (seedToByte.byteToSeed(byteHex) == seedToByte.byteToSeed(finalSeed))
            {
                passed[0] += 1;
            }
            else
            {
                Debug.Log("Test for seed size of: " + i + " failed.");
            }
        }

        return(passed);
    }
예제 #9
0
    public int[] testBreakPoints()
    {
        int[] passed = new int[2];

        string testHex = "FFFFAAAAFFFFAAAA";

        byte[]     testHexSeed = SeedToByte.HexStringToByteArray(testHex);
        List <int> tempList    = SeedToByte.customList(4, 8, 6, 2, 2);
        BitArray   seedBits    = seedToByte.byteToBits(testHexSeed);

        int[]  actions   = seedToByte.bitToActions(seedBits, tempList);
        byte[] finalSeed = SeedToByte.seedConverterUniversal(actions, tempList);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test for converting 64 bit seed to action list and back failed");
        }

        testHex     = "FFFFAAAAFFFFAAAAFFFFAAAAFFFFAAAA";
        testHexSeed = SeedToByte.HexStringToByteArray(testHex);
        tempList    = SeedToByte.customList(4, 8, 6, 2, 4);
        seedBits    = seedToByte.byteToBits(testHexSeed);
        actions     = seedToByte.bitToActions(seedBits, tempList);
        finalSeed   = SeedToByte.seedConverterUniversal(actions, tempList);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test for converting 128 bit seed to action list and back failed");
        }

        return(passed);
    }
예제 #10
0
    public int[] testMultipleSizeSeeds()
    {
        int[] passed = new int[2];

        string testHex = "FFFFAAAAFFFFAAAAFFFFDDDDFFFF";

        byte[] testHexSeed = SeedToByte.HexStringToByteArray(testHex);
        byte[] testRunSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        List <int> tempList1 = SeedToByte.customList(4, 4, 2, 4, 4);
        List <int> tempList2 = SeedToByte.customList(3, 4, 2, 4, 4);

        BitArray seedBits1 = seedToByte.byteToBits(testRunSeed);
        BitArray seedBits2 = seedToByte.byteToBits(testHexSeed);

        int[] actions1 = seedToByte.bitToActions(seedBits1, tempList1);
        int[] actions2 = seedToByte.bitToActions(seedBits2, tempList1);

        byte[] finalSeed1 = SeedToByte.seedConverterUniversal(actions1, tempList1);
        byte[] finalSeed2 = SeedToByte.seedConverterUniversal(actions2, tempList1);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testRunSeed) == seedToByte.byteToSeed(finalSeed1))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test 1 for converting 112 bit seed to action list and back failed");
        }

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed2))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test 2 for converting 112 bit seed to action list and back failed");
        }

        testHexSeed = new byte[14];
        testRunSeed = OTPworker.randomSeedGenerator(testRunSeed);

        if (testRunSeed[13] > 7)
        {
            testRunSeed[13] = (byte)((int)testRunSeed[13] % 7);
        }

        BitArray seedBits = seedToByte.byteToBits(testHexSeed);

        int[] actions3 = seedToByte.bitToActions(seedBits, tempList2);

        byte[] finalSeed3 = SeedToByte.seedConverterUniversal(actions3, tempList2);

        passed[1] += 1;
        if (seedToByte.byteToSeed(testHexSeed) == seedToByte.byteToSeed(finalSeed3))
        {
            passed[0] += 1;
        }
        else
        {
            Debug.Log("Test for converting 108 bit seed to action list and back failed");
        }

        return(passed);
    }
예제 #11
0
 public void Start()
 {
     seedToByte = GetComponent <SeedToByte>();
 }
예제 #12
0
    // Creates a custom learn mode - does the heavy lifting for the above two functions
    public static string learnTest(string input, bool random, bool iterative, bool tryToBreak)
    {
        string[] stringInputs = input.Split(null);
        int[]    scenes       = new int[InteractableConfig.SitesPerGame];
        int[]    actions      = new int[InteractableConfig.SitesPerGame + (InteractableConfig.SitesPerGame * InteractableConfig.ActionsPerSite * 2)];
        if (stringInputs.Length <= 0 || input == null || input == "")
        {
            return("Please enter at least one scene name for the custom learn path.");
        }
        Debug.Log("Input: " + input);
        Debug.Log("String input length: " + stringInputs.Length);

        for (int i = 0; i < InteractableConfig.SitesPerGame; i++)
        {
            // queue up the scenes entered by user into a seed
            if (i < stringInputs.Length)
            {
                if (sceneIndeces.ContainsKey(stringInputs[i]))
                {
                    scenes[i] = sceneIndeces[stringInputs[i]];
                }
                else if (fuzzySceneNames.ContainsKey(stringInputs[i]))
                {
                    scenes[i] = sceneIndeces[fuzzySceneNames[stringInputs[i]]];
                }
                else
                {
                    Debug.Log("Do not recognize scene name: " + stringInputs[i]);
                    return("Do not recognize scene name: " + stringInputs[i]);
                }
            }
            else
            {
                scenes[i] = 2;
            }
        }

        int counter = 0;

        // Create custom seed using the chosen scenes
        for (int i = 0; i < InteractableConfig.SitesPerGame; i++)
        {
            actions[i + i * InteractableConfig.ActionsPerSite * 2] = scenes[i];

            for (int j = 0; j < InteractableConfig.ActionsPerSite; j++)
            {
                if (iterative)
                {
                    actions[j * 2 + 1 + i + i * InteractableConfig.ActionsPerSite * 2] = counter % 16;
                }
                else if (random)
                {
                    actions[j * 2 + 1 + i + i * InteractableConfig.ActionsPerSite * 2] = UnityEngine.Random.Range(0, 100) % 16;
                }
                else if (tryToBreak)
                {
                    actions[j * 2 + 1 + i + i * InteractableConfig.ActionsPerSite * 2] = j + 13;
                }
                else
                {
                    actions[j * 2 + 1 + i + i * InteractableConfig.ActionsPerSite * 2] = j % 16;
                }

                actions[j * 2 + 2 + i + i * InteractableConfig.ActionsPerSite * 2] = j % 4;

                //if (iterative)
                //    Debug.Log("Counter " + counter % 16);
                counter++;
            }
        }

        SeedToByte seeds = new SeedToByte();
        string     seed  = seeds.getSeed(actions);

        Debug.Log("Artificial seed: " + seed);

        InteractablePathManager.SeedString = seed;
        InteractablePath.ResetPath();
        InteractablePathManager.Reset();
        if (GameManager.V2Menus)
        {
            WorldManager.Reset();
        }
        else
        {
            LevelSetManager.ResetCurrentLevels();
        }


        for (int i = 0; i < scenes.Length; i++)
        {
            if (GameManager.V2Menus)
            {
                WorldManager.Add(scenes[i]);
            }
            else
            {
                LevelSetManager.AddLevel(scenes[i]);
            }
        }

        GameManager.Mode  = GameMode.Rehearsal;
        GameManager.State = GameState.Play;
        InteractablePathManager.Initalize();

        if (fuzzySceneNames.ContainsKey(stringInputs[0]))
        {
            SceneManager.LoadScene(fuzzySceneNames[stringInputs[0]]);
            return("Loading custom seed. Scene: " + fuzzySceneNames[stringInputs[0]]);
        }
        else
        {
            Debug.Log("Could not find scene named " + stringInputs[0]);
        }

        SceneManager.LoadScene(stringInputs[0]);

        return("Loading custom seed. Scene: " + stringInputs[0]);
    }