Beispiel #1
0
        public void TestExtensionCloning()
        {
            var puppetLevel1   = PuppetLevel.Create(masterBuildControl: true);
            var puppetSpecial1 = new PuppetLevelAddition1(puppetLevel1, true); //give value for Addition1
            var puppetSpecial2 = puppetLevel1.GetSpecialised <PuppetLevelAddition2>();


            var puppetLevel1C = puppetLevel1.Clone();
            PuppetLevelAddition1 puppetSpecial1C = puppetLevel1C.GetSpecialised <PuppetLevelAddition1>();
            PuppetLevelAddition2 puppetSpecial2C = puppetLevel1C.GetSpecialised <PuppetLevelAddition2>();

            //Value Conservation
            Assert.True(puppetLevel1C.MasterBuildControl);
            Assert.True(puppetSpecial1C.MasterBuildControl);
            Assert.True(puppetSpecial2C.MasterBuildControl);
            //Instance independence
            Assert.NotEqual(puppetLevel1, puppetLevel1C);
            Assert.NotEqual(puppetSpecial1, puppetSpecial1C);
            Assert.NotEqual(puppetSpecial2, puppetSpecial2C);
            //Value independence
            puppetLevel1.MasterBuildControl = false;
            puppetSpecial1.Addition1        = false;
            puppetSpecial2C.Addition2       = true;
            Assert.NotEqual(puppetLevel1.MasterBuildControl, puppetLevel1C.MasterBuildControl);
            Assert.NotEqual(puppetSpecial1.MasterBuildControl, puppetSpecial1C.MasterBuildControl);
            Assert.NotEqual(puppetSpecial2.MasterBuildControl, puppetSpecial2C.MasterBuildControl);
            Assert.NotEqual(puppetSpecial1.Addition1, puppetSpecial1C.Addition1);
            Assert.NotEqual(puppetSpecial2.Addition2, puppetSpecial2C.Addition2);
        }
Beispiel #2
0
        /*private static void TestWorld()
         * {
         *  //game data
         *  var root = new RootKey("root");
         *
         *  YieldManager ym = new YieldManagerImpl(new Key(root, "yield"));
         *  var food = new YieldType("food", ym);
         *  var production = new YieldType("production", ym);
         *  var commerce = new YieldType("commerce", ym);
         *
         *  var resTb = new YieldModifyingSSFR<TerrainBiome>(WorldType.World, new Key(root, "tb"), false, Terrain);
         *  var grassland = new TerrainBiome("grassland", resTb, ym, Addition, new double[] {2, 0, 0});
         *  var plains = new TerrainBiome("plains", resTb, ym, Addition, new double[] {1, 1, 0});
         *  var desert = new TerrainBiome("desert", resTb, ym, Addition, new double[] {0, 1, 0});
         *  var tundra = new TerrainBiome("tundra", resTb, ym, Addition, new double[] {1, 0, 0});
         *  var ice = new TerrainBiome("ice", resTb, ym, Addition, new double[] {0, 0, 0});
         *  var resTv = new YieldModifyingSMFR<TerrainVegetation>(WorldType.World, new Key(root, "tv"), Terrain);
         *  var jungle = new TerrainVegetation("jungle", resTv, ym, Addition, new double[] {0, -1, -1});
         *  var forest = new TerrainVegetation("forest", resTv, ym, Addition, new double[] {0, 1, 0});
         *  var pineForest = new TerrainVegetation("pine forest", resTv, ym, Addition, new double[] {0, 1, 0});
         *  var resTl = new YieldModifyingSSFR<TerrainLandform>(WorldType.World, new Key(root, "tl"), false, Terrain);
         *  var flatland = new TerrainLandform("flatland", resTl, ym, Addition, new double[] {0, 0, 0});
         *  var hills = new TerrainLandform("hills", resTl, ym, Addition, new double[] {-1, 1, 0});
         *  var mountains = new TerrainLandform("mountains", resTl, ym, Addition, new double[] {-2, 1, 0});
         *  var highMountains = new TerrainLandform("high mountains", resTl, ym, Addition, new double[] {-2, 0, -1});
         *
         *  //civs
         *  var civMan = new CivilizationRegister(new Key(root, "civs"), 4);
         *  var rome = new Civilization("Rome", civMan);
         *  var egypt = new Civilization("Egypt", civMan);
         *
         *  //init
         *  var fw = new FeatureWorld(2, ym);
         *  fw.Register(resTb);
         *  fw.Register(resTv);
         *  fw.Register(resTl);
         *  fw.Register(civMan.Resolver);
         *  fw.Lock();
         *
         *  //world creation
         *  var world = new TileWorld(fw, 5, 5);
         *
         *  // ReSharper disable once InconsistentNaming
         *  var tile3_3 = world[3, 3];
         *
         * Console.WriteLine(grassland.HasFeature(tile3_3));
         *  Console.WriteLine(flatland.HasFeature(tile3_3));
         *  Console.WriteLine(jungle.HasFeature(tile3_3));
         *  Console.WriteLine(mountains.HasFeature(tile3_3));
         *  Console.WriteLine(flatland.Id);
         *  Console.WriteLine(hills.Id);
         *  Console.WriteLine(mountains.Id);
         *  Console.WriteLine();
         *  Console.WriteLine(
         *      $"{world.CalcYield(3, 3, food)}, {world.CalcYield(3, 3, production)}, {world.CalcYield(3, 3, commerce)}");
         *  forest.AddFeature(tile3_3);
         *  Console.WriteLine(
         *      $"{world.CalcYield(3, 3, food)}, {world.CalcYield(3, 3, production)}, {world.CalcYield(3, 3, commerce)}");
         *  hills.AddFeature(tile3_3);
         *  Console.WriteLine(
         *      $"{world.CalcYield(3, 3, food)}, {world.CalcYield(3, 3, production)}, {world.CalcYield(3, 3, commerce)}");
         *  Console.WriteLine(grassland.HasFeature(tile3_3));
         *  Console.WriteLine(forest.HasFeature(tile3_3));
         *  Console.WriteLine(hills.HasFeature(tile3_3));
         *
         *  Console.WriteLine($"Owner: 2,3={civMan.GetOwner(world[2, 3])?.Name ?? "NoMensLand"}");
         *  Console.WriteLine(
         *      $"Rome Vision={rome.GetVision(world[2, 3])}, Egypt Vision={egypt.GetVision(world[2, 3])}, ");
         *  rome.Own(world[2, 3]);
         *  Console.WriteLine($"Owner: 2,3={civMan.GetOwner(world[2, 3])?.Name ?? "NoMensLand"}");
         *  Console.WriteLine(
         *      $"Rome Vision={rome.GetVision(world[2, 3])}, Egypt Vision={egypt.GetVision(world[2, 3])}, ");
         *  egypt.Own(world[2, 3]);
         *  Console.WriteLine($"Owner: 2,3={civMan.GetOwner(world[2, 3])?.Name ?? "NoMensLand"}");
         *  Console.WriteLine(
         *      $"Rome Vision={rome.GetVision(world[2, 3])}, Egypt Vision={egypt.GetVision(world[2, 3])}, ");
         *  Console.WriteLine($"Owner: 3,2={civMan.GetOwner(world[3, 2])?.Name ?? "NoMensLand"}");
         *
         *
         *  Console.ReadKey();
         *
         *  var sw = new Stopwatch();
         *
         *  //big world alloc
         *  sw.Start();
         *  const int worldSize = 5000;
         *  world = new TileWorld(fw, worldSize, worldSize);
         *  var world2 = new TileWorld(fw, worldSize, worldSize);
         *  sw.Stop();
         *  GC.Collect();
         *  Console.WriteLine($"ms:{sw.ElapsedMilliseconds}");
         *
         *  //prepair multithreading test
         *  var wInterface = new WorldInterfaceImpl(world2);
         *  var monitor = new object();
         *  bool[] flag = {
         *      true
         *  };
         *
         *  var thread2 = new Thread(() => {
         *      lock (monitor) Monitor.Wait(monitor);
         *      Console.WriteLine("Thread 2 stopped waiting");
         *      var sw2 = new Stopwatch();
         *      sw2.Start();
         *      wInterface.Execute();
         *      sw2.Stop();
         *      Console.WriteLine($"Thread 2 took {sw2.Elapsed.TotalMilliseconds}ms");
         *      lock (monitor) Monitor.Pulse(monitor);
         *      lock (monitor) Monitor.Wait(monitor);
         *      int workLoops = 0;
         *      int allLoops = 0;
         *      int j = 0;
         *      long lastTiming = 0;
         *      //Thread.Sleep(50);
         *      while (flag[0]) {
         *          j++;
         *          sw.Restart();
         *          if (wInterface.Execute()) {
         *              sw.Stop();
         *              lastTiming += sw.ElapsedTicks;
         *              workLoops++;
         *              allLoops += j;
         *              j = 0;
         *          }
         *      }
         *
         *      Console.WriteLine(
         *          $"Thread 2 made {workLoops}/{allLoops} loops. Took: {new TimeSpan(lastTiming).TotalMilliseconds}ms");
         *  });
         *  thread2.Start();
         *
         *  //random updates
         *  world.RegisterUpdate(wInterface.ScheduleUpdate);
         *  ISimpleFeature[] allFeatures = {
         *      desert, flatland, forest, grassland, highMountains, hills, ice, jungle, mountains, pineForest, plains,
         *      tundra
         *  };
         *  var rnd = new Random();
         *  Console.WriteLine("random updates");
         *
         *  sw.Start();
         *  for (int i = 0; i < 1_000_000; i++) {
         *      allFeatures[rnd.Next(allFeatures.Length)].AddFeature(world[rnd.Next(worldSize), rnd.Next(worldSize)]);
         *  }
         *  sw.Stop();
         *  lock (monitor) Monitor.Pulse(monitor);
         *  Console.WriteLine($"random updates done. took {sw.ElapsedMilliseconds}ms");
         *  lock (monitor) Monitor.Wait(monitor);
         *  Console.ReadKey();
         *
         *
         *  Console.WriteLine("random updates parallel");
         *  lock (monitor) Monitor.Pulse(monitor);
         *  for (int i = 0; i < 1_000_000; i++) {
         *      allFeatures[rnd.Next(allFeatures.Length)].AddFeature(world[rnd.Next(worldSize), rnd.Next(worldSize)]);
         *  }
         *  flag[0] = false;
         *  Console.WriteLine("random updates parallel done");
         *
         *
         *  Console.ReadKey();
         *  Console.WriteLine(grassland.HasFeature(tile3_3));
         *  Console.WriteLine(mountains.HasFeature(tile3_3));
         *
         *  Console.ReadKey();
         * }*/


        private static void TestPuppetLevel()
        {
            var puppetLevel1   = PuppetLevel.Create(masterBuildControl: true);
            var puppetSpecial1 = new PuppetLevelAddition1(puppetLevel1);
            var puppetSpecial2 = puppetLevel1.GetSpecialised <PuppetLevelAddition2>();

            Console.WriteLine(
                $"{puppetLevel1.MasterBuildControl} {puppetSpecial1.MasterBuildControl} {puppetSpecial2.MasterBuildControl}");
            var puppetSpecial21 = puppetSpecial1.GetSpecialised <PuppetLevelAddition2>();

            Console.WriteLine(puppetSpecial2 == puppetSpecial21);
            Console.WriteLine();
            puppetSpecial2.Addition2 = true;

            var puppetLevel1C   = puppetLevel1.Clone();
            var puppetSpecial1C = puppetLevel1C.GetSpecialised <PuppetLevelAddition1>();
            var puppetSpecial2C = puppetLevel1C.GetSpecialised <PuppetLevelAddition2>();

            Console.WriteLine(
                $"{puppetLevel1.MasterBuildControl} {puppetSpecial1.MasterBuildControl} {puppetSpecial2.MasterBuildControl}");
            Console.WriteLine(
                $"{puppetLevel1 == puppetLevel1C} {puppetSpecial1 == puppetSpecial1C} {puppetSpecial2 == puppetSpecial2C}");
            Console.WriteLine();
            puppetSpecial1C.Addition1 = true;
            puppetSpecial2.Addition2  = false;

            Console.WriteLine($"{puppetSpecial1.Addition1} vs {puppetSpecial1C.Addition1}");
            Console.WriteLine($"{puppetSpecial2.Addition2} vs {puppetSpecial2C.Addition2}");
        }
Beispiel #3
0
        public void TestExtensionValueConservation()
        {
            var puppetLevel1   = PuppetLevel.Create(masterBuildControl: true);
            var puppetSpecial1 = puppetLevel1.GetSpecialised <PuppetLevelAddition1>();

            Assert.True(puppetLevel1.MasterBuildControl);
            Assert.Equal(puppetLevel1.MasterBuildControl, puppetSpecial1.MasterBuildControl);
        }
Beispiel #4
0
        public void TestExtensionInstanceConsistency()
        {
            var puppetLevel1    = PuppetLevel.Create();
            var puppetSpecial1  = puppetLevel1.GetSpecialised <PuppetLevelAddition1>();
            var puppetSpecial2  = new PuppetLevelAddition2(puppetLevel1);
            var puppetSpecial3  = new PuppetLevelAddition3(puppetSpecial2);
            var puppetSpecial11 = puppetSpecial3.GetSpecialised <PuppetLevelAddition1>();
            var puppetSpecial21 = puppetLevel1.GetSpecialised <PuppetLevelAddition2>();
            var puppetSpecial31 = puppetSpecial1.GetSpecialised <PuppetLevelAddition3>();

            Assert.True(puppetSpecial1 == puppetSpecial11);
            Assert.True(puppetSpecial2 == puppetSpecial21);
            Assert.True(puppetSpecial3 == puppetSpecial31);
        }