Exemple #1
0
        public TomeOfChaos Tome_FromNew(string topSeed)
        {
            var tome = new TomeOfChaos(topSeed);
            AbstractGenerator topRNG;
            AbstractGenerator mapRNG;

            // Any time the sequence of .Next() calls to an RNG changes,
            // the same seed will no longer produce the same world.
            tome.Generators["Top"]       = topRNG = new NR3Generator(tome.TopSeedInt);
            tome.Generators["MapTop"]    = mapRNG = new NR3Generator(topRNG.Next());
            tome.Generators["Learnable"] = new NR3Generator(topRNG.Next());

            tome.MapGenerators[MapEnum.TackerFarm]    = new NR3Generator(mapRNG.Next());
            tome.MapGenerators[MapEnum.TownBarricade] = new NR3Generator(mapRNG.Next());

            return(tome);
        }
Exemple #2
0
        public void Serializing_NR3Generator_keeps_sequence()
        {
            var r1 = new NR3Generator();

            for (var i = 0; i < 10; i++)
            {
                int toss = r1.Next();
            }

            byte[] ser_r1 = ObjectToByteArray(r1);
            string b64_r1 = Convert.ToBase64String(ser_r1);


            var serializer = new Serializer();
            //var writer = new StringWriter();
            //writer.Write(b64_r1);

            var save = new game_save {
                Generator = b64_r1
            };
            var yaml_r1 = serializer.Serialize(save);


            var reader       = new StringReader(yaml_r1);
            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(PascalCaseNamingConvention.Instance)
                               .Build();

            var save_2 = deserializer.Deserialize <game_save>(yaml_r1);


            byte[] ser_r2 = Convert.FromBase64String(save_2.Generator);
            var    r2     = (NR3Generator)ByteArrayToObject(ser_r2);

            for (var j = 0; j < 100; j++)
            {
                int r1_out = r1.Next();
                int r2_out = r2.Next();

                Assert.That(r1_out, Is.EqualTo(r2_out));
            }
        }