示例#1
0
        public void TestDefaultTileset(string environmentFilePath)
        {
            using var fileStream = File.OpenRead(environmentFilePath);
            var environment = MapEnvironment.Parse(fileStream);

            Assert.IsTrue(environment.IsDefaultTileset());
        }
示例#2
0
        public void TestDefaultMapEnvironment()
        {
            // Get World Editor default environment file.
            using var defaultEnvironmentStream = File.OpenRead(TestDataProvider.GetFile(@"MapFiles\DefaultMapFiles\war3map.w3e"));
            var defaultMapEnvironment = MapEnvironment.Parse(defaultEnvironmentStream, true);

            defaultEnvironmentStream.Position = 0;

            // Get War3Net default environment file.
            var mapEnvironment = MapEnvironment.Default;

            // Update defaults that are different.
            var tileEnumerator = defaultMapEnvironment.GetEnumerator();

            foreach (var tile in mapEnvironment)
            {
                tileEnumerator.MoveNext();
                tile.Variation      = tileEnumerator.Current.Variation;
                tile.CliffVariation = tileEnumerator.Current.CliffVariation;
            }

            // Compare files.
            using var mapEnvironmentStream = new MemoryStream();
            mapEnvironment.SerializeTo(mapEnvironmentStream, true);
            mapEnvironmentStream.Position = 0;

            StreamAssert.AreEqual(defaultEnvironmentStream, mapEnvironmentStream);
        }
示例#3
0
        public void TestGenerateMapPreviewIcons(string inputFolder)
        {
            var mapInfo        = MapInfo.Parse(File.OpenRead(Path.Combine(inputFolder, MapInfo.FileName)));
            var mapEnvironment = MapEnvironment.Parse(File.OpenRead(Path.Combine(inputFolder, MapEnvironment.FileName)));
            var mapUnits       = MapUnits.Parse(File.OpenRead(Path.Combine(inputFolder, MapUnits.FileName)));

            var expected = MapPreviewIcons.Parse(File.OpenRead(Path.Combine(inputFolder, MapPreviewIcons.FileName)));
            var actual   = new MapPreviewIcons(mapInfo, mapEnvironment, mapUnits);

            var expectedEnumerator = expected.GetEnumerator();
            var actualEnumerator   = actual.GetEnumerator();

            while (true)
            {
                if (expectedEnumerator.MoveNext() & actualEnumerator.MoveNext())
                {
                    var expectedIcon = expectedEnumerator.Current;
                    var actualIcon   = actualEnumerator.Current;

                    const int delta = 1;
                    Assert.AreEqual(expectedIcon.IconType, actualIcon.IconType);
                    Assert.AreEqual(expectedIcon.X, actualIcon.X, delta);
                    Assert.AreEqual(expectedIcon.Y, actualIcon.Y, delta);
                    Assert.AreEqual(expectedIcon.Color.ToArgb(), actualIcon.Color.ToArgb());
                }
                else if (expectedEnumerator.Current != null || actualEnumerator.Current != null)
                {
                    Assert.Fail("Expected and actual icon count are not the same.");
                }
                else
                {
                    break;
                }
            }
        }
示例#4
0
        public void TestParseMapEnvironment(string environmentFilePath)
        {
            using var original  = FileProvider.GetFile(environmentFilePath);
            using var recreated = new MemoryStream();

            MapEnvironment.Parse(original, true).SerializeTo(recreated, true);
            StreamAssert.AreEqual(original, recreated, true);
        }
示例#5
0
	public void setUp() {
		ExtendableMap aMap = new ExtendableMap();
		aMap.addBidirectionalLink("A", "B", 5.0);
		aMap.addBidirectionalLink("A", "C", 6.0);
		aMap.addBidirectionalLink("B", "C", 4.0);
		aMap.addBidirectionalLink("C", "D", 7.0);
		aMap.addUnidirectionalLink("B", "E", 14.0);

		me = new MapEnvironment(aMap);
		ma = new MapAgent(me.getMap(), me, new UniformCostSearch(),
				new String[] { "A" });
	}
示例#6
0
	public void testAlreadyAtGoal() {
		MapEnvironment me = new MapEnvironment(aMap);
		OnlineDFSAgent agent = new OnlineDFSAgent(new OnlineSearchProblem(
				MapFunctionFactory.getActionsFunction(aMap),
				new DefaultGoalTest("A"), new MapStepCostFunction(aMap)),
				MapFunctionFactory.getPerceptToStateFunction());
		me.addAgent(agent, "A");
		me.addEnvironmentView(new TestEnvironmentView());
		me.stepUntilDone();

		Assert.assertEquals("Action[name==NoOp]->", envChanges.ToString());
	}
示例#7
0
        public void testNoPath()
        {
            MapEnvironment me = new MapEnvironment(aMap);
            SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, new UniformCostSearch <string, MoveToAction>(), new string[] { "A" });

            me.addAgent(ma, "E");
            me.AddEnvironmentView(new TestEnvironmentView(envChanges));
            me.StepUntilDone();

            Assert.AreEqual(
                "CurrentLocation=In(E), Goal=In(A):Action[name==NoOp]:METRIC[nodesExpanded]=1:METRIC[queueSize]=0:METRIC[maxQueueSize]=1:METRIC[pathCost]=0:Action[name==NoOp]:",
                envChanges.ToString());
        }
示例#8
0
	public void testNoPath() {
		MapEnvironment me = new MapEnvironment(aMap);
		MapAgent ma = new MapAgent(me.getMap(), me, new UniformCostSearch(),
				new String[] { "A" });
		me.addAgent(ma, "E");
		me.addEnvironmentView(new TestEnvironmentView());
		me.stepUntilDone();

		Assert
				.assertEquals(
						"CurrentLocation=In(E), Goal=In(A):Action[name==NoOp]:METRIC[pathCost]=0:METRIC[maxQueueSize]=1:METRIC[queueSize]=0:METRIC[nodesExpanded]=1:Action[name==NoOp]:",
						envChanges.ToString());
	}
示例#9
0
        public void setUp()
        {
            ExtendableMap aMap = new ExtendableMap();

            aMap.addBidirectionalLink("A", "B", 5.0);
            aMap.addBidirectionalLink("A", "C", 6.0);
            aMap.addBidirectionalLink("B", "C", 4.0);
            aMap.addBidirectionalLink("C", "D", 7.0);
            aMap.addUnidirectionalLink("B", "E", 14.0);

            me = new MapEnvironment(aMap);
            ma = new SimpleMapAgent(me.getMap(), me, new UniformCostSearch <string, MoveToAction>(),
                                    new string[] { "A" });
        }
        public void test_A_StartingAtGoal()
        {
            ExtendableMap aMap = new ExtendableMap();

            MapEnvironment me = new MapEnvironment(aMap);
            SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, search, new string[] { "A" });

            me.addAgent(ma, "A");
            me.AddEnvironmentView(new BDSEnvironmentView(envChanges));
            me.StepUntilDone();

            Assert.AreEqual(
                "CurrentLocation=In(A), Goal=In(A):Action[name==NoOp]:METRIC[nodesExpanded]=0:METRIC[queueSize]=0:METRIC[maxQueueSize]=0:METRIC[pathCost]=0:Action[name==NoOp]:",
                envChanges.ToString());
        }
示例#11
0
        public void testNormalSearchGraphSearchMinFrontier()
        {
            MapEnvironment me = new MapEnvironment(aMap);
            UniformCostSearch <string, MoveToAction> ucSearch = new UniformCostSearch <string, MoveToAction>(new GraphSearchReducedFrontier <string, MoveToAction>());

            SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, ucSearch, new string[] { "D" });

            me.addAgent(ma, "A");
            me.AddEnvironmentView(new TestEnvironmentView(envChanges));
            me.StepUntilDone();

            Assert.AreEqual(
                "CurrentLocation=In(A), Goal=In(D):Action[name==moveTo, location==C]:Action[name==moveTo, location==D]:METRIC[nodesExpanded]=3:METRIC[queueSize]=1:METRIC[maxQueueSize]=2:METRIC[pathCost]=13:Action[name==NoOp]:",
                envChanges.ToString());
        }
示例#12
0
        public static MapPreviewIcons GenerateIcons(MapInfo info, MapEnvironment environment, MapUnits units)
        {
            var padding = info.CameraBoundsComplements;

            var minX  = environment.Left + (128 * padding.Left);
            var width = environment.Right - (128 * padding.Right) - minX;

            var minY   = environment.Bottom + (128 * padding.Bottom);
            var height = environment.Top - (128 * padding.Top) - minY;

            var ratio = width / height;
            var sizeX = 255 * (ratio > 1 ? 1 : ratio);
            var sizeY = 255 * (ratio > 1 ? 1 / ratio : 1);

            var lowerX = 1 + (0.5f * (255 - sizeX));
            var upperY = 1 + (0.5f * (255 + sizeY));

            sizeX /= width;
            sizeY /= height;

            var icons = new List <PreviewIcon>();

            if (units != null)
            {
                foreach (var unit in units.Units)
                {
                    if (MapPreviewIconProvider.TryGetIcon(unit.TypeId, unit.OwnerId, out var iconType, out var iconColor))
                    {
                        icons.Add(new PreviewIcon()
                        {
                            IconType = iconType,
                            // X = (byte)(lowerX + (sizeX * (unit.Position.X - minX))),
                            // Y = (byte)(upperY - (sizeY * (unit.Position.Y - minY))),
                            X     = (byte)(0.0f + lowerX + (sizeX * (unit.Position.X - minX))),
                            Y     = (byte)(0.5f + upperY - (sizeY * (unit.Position.Y - minY))),
                            Color = iconColor,
                        });
                    }
                }
            }

            return(new MapPreviewIcons(MapPreviewIconsFormatVersion.Normal)
            {
                Icons = icons,
            });
        }
        public void test_AB_BothWaysPath()
        {
            ExtendableMap aMap = new ExtendableMap();

            aMap.addBidirectionalLink("A", "B", 5.0);

            MapEnvironment me = new MapEnvironment(aMap);
            SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, search, new string[] { "B" });

            me.addAgent(ma, "A");
            me.AddEnvironmentView(new BDSEnvironmentView(envChanges));
            me.StepUntilDone();

            Assert.AreEqual(
                "CurrentLocation=In(A), Goal=In(B):Action[name==moveTo, location==B]:METRIC[nodesExpanded]=1:METRIC[queueSize]=1:METRIC[maxQueueSize]=2:METRIC[pathCost]=5:Action[name==NoOp]:",
                envChanges.ToString());
        }
示例#14
0
	public void testNoPath() {
		aMap = new ExtendableMap();
		aMap.addBidirectionalLink("A", "B", 1.0);
		MapEnvironment me = new MapEnvironment(aMap);
		OnlineDFSAgent agent = new OnlineDFSAgent(new OnlineSearchProblem(
				MapFunctionFactory.getActionsFunction(aMap),
				new DefaultGoalTest("X"), new MapStepCostFunction(aMap)),
				MapFunctionFactory.getPerceptToStateFunction());
		me.addAgent(agent, "A");
		me.addEnvironmentView(new TestEnvironmentView());

		me.stepUntilDone();

		Assert
				.assertEquals(
						"Action[name==moveTo, location==B]->Action[name==moveTo, location==A]->Action[name==moveTo, location==B]->Action[name==moveTo, location==A]->Action[name==NoOp]->",
						envChanges.ToString());
	}
        public void test_ABCDEF_ReverseFirstButNotFromOriginal()
        {
            ExtendableMap aMap = new ExtendableMap();

            aMap.addBidirectionalLink("A", "B", 5.0);
            aMap.addBidirectionalLink("B", "C", 5.0);
            aMap.addBidirectionalLink("C", "D", 5.0);
            aMap.addBidirectionalLink("D", "E", 5.0);
            aMap.addBidirectionalLink("E", "F", 5.0);
            aMap.addUnidirectionalLink("E", "A", 5.0);

            MapEnvironment me = new MapEnvironment(aMap);
            SimpleMapAgent ma = new SimpleMapAgent(me.getMap(), me, search, new string[] { "F" });

            me.addAgent(ma, "A");
            me.AddEnvironmentView(new BDSEnvironmentView(envChanges));
            me.StepUntilDone();

            Assert.AreEqual(
                "CurrentLocation=In(A), Goal=In(F):Action[name==moveTo, location==B]:Action[name==moveTo, location==C]:Action[name==moveTo, location==D]:Action[name==moveTo, location==E]:Action[name==moveTo, location==F]:METRIC[nodesExpanded]=6:METRIC[queueSize]=1:METRIC[maxQueueSize]=2:METRIC[pathCost]=25:Action[name==NoOp]:",
                envChanges.ToString());
        }
示例#16
0
        public void SaveMaps(ICLIFlags toolFlags)
        {
            string basePath;

            if (toolFlags is ExtractMapEnvFlags flags)
            {
                basePath = flags.OutputPath;
            }
            else
            {
                throw new Exception("no output path");
            }

            basePath = Path.Combine(basePath, "Environments");

            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            if (!flags.SkipMapEnvironmentLUT && File.Exists(Path.Combine(basePath, "SPILUT", "config.ocio")))
            {
                File.Delete(Path.Combine(basePath, "SPILUT", "config.ocio"));
            }

            HashSet <KeyValuePair <ulong, string> > done = new HashSet <KeyValuePair <ulong, string> >();

            foreach (ulong metaKey in TrackedFiles[0x9F])
            {
                STUMap map = GetInstance <STUMap>(metaKey);
                if (map == null)
                {
                    continue;
                }

                MapInfo mapInfo = GetMap(metaKey);
                mapInfo.Name  = mapInfo.Name ?? "Title Screen";
                mapInfo.NameB = mapInfo.NameB ?? mapInfo.Name;

                ulong dataKey = map.MapDataResource1;

                using (Stream data = OpenFile(dataKey))
                {
                    if (data == null)
                    {
                        continue;
                    }

                    using (BinaryReader dataReader = new BinaryReader(data))
                    {
                        MapEnvironment env = dataReader.Read <MapEnvironment>();

                        string fname = $"ow_map_{GetValidFilename($"{mapInfo.NameB}_{GUID.Index(mapInfo.MetadataGUID):X}")}";

                        if (!flags.SkipMapEnvironmentSound && done.Add(new KeyValuePair <ulong, string>(env.MapEnvironmentSound, mapInfo.Name)))
                        {
                            SaveSound(flags, basePath, Path.Combine("Sound", GetValidFilename($"{mapInfo.NameB}_{GUID.Index(mapInfo.MetadataGUID):X}")), env.MapEnvironmentSound);
                        }
                        if (!flags.SkipMapEnvironmentLUT && done.Add(new KeyValuePair <ulong, string>(env.LUT, mapInfo.Name)))
                        {
                            SaveTex(flags, basePath, "LUT", fname, env.LUT);
                            SaveLUT(flags, basePath, "SPILUT", fname, env.LUT, Path.Combine(basePath, "SPILUT", "config.ocio"), mapInfo);
                        }
                        if (!flags.SkipMapEnvironmentBlendCubemap && done.Add(new KeyValuePair <ulong, string>(env.BlendEnvironmentCubemap, mapInfo.Name)))
                        {
                            SaveTex(flags, basePath, "BlendCubemap", fname, env.BlendEnvironmentCubemap);
                        }
                        if (!flags.SkipMapEnvironmentGroundCubemap && done.Add(new KeyValuePair <ulong, string>(env.GroundEnvironmentCubemap, mapInfo.Name)))
                        {
                            SaveTex(flags, basePath, "GroundCubemap", fname, env.GroundEnvironmentCubemap);
                        }
                        if (!flags.SkipMapEnvironmentSkyCubemap && done.Add(new KeyValuePair <ulong, string>(env.SkyEnvironmentCubemap, mapInfo.Name)))
                        {
                            SaveTex(flags, basePath, "SkyCubemap", fname, env.SkyEnvironmentCubemap);
                        }
                        if (!flags.SkipMapEnvironmentSkybox && done.Add(new KeyValuePair <ulong, string>(env.SkyboxModel ^ env.SkyboxModelLook, mapInfo.Name)))
                        {
                            SaveMdl(flags, basePath, Path.Combine("Skybox", GetValidFilename($"{mapInfo.NameB}_{GUID.Index(mapInfo.MetadataGUID):X}")), env.SkyboxModel, env.SkyboxModelLook);
                        }
                        if (!flags.SkipMapEnvironmentEntity && done.Add(new KeyValuePair <ulong, string>(env.EntityDefinition, mapInfo.Name)))
                        {
                            SaveEntity(flags, basePath, Path.Combine("Entity", GetValidFilename($"{mapInfo.NameB}_{GUID.Index(mapInfo.MetadataGUID):X}")), env.EntityDefinition);
                        }

                        InfoLog("Saved Environment data for {0}", mapInfo.NameB);
                    }
                }
            }
        }
示例#17
0
 /**
  * Creates a scenario.
  *
  * @param env
  *            a map-based environment. Note that the contained map must be
  *            of type {@link ExtendableMap}
  * @param agentMap
  *            a map reflecting the knowledge of the agent about the
  *            environment
  * @param agentLoc
  *            initial location of the agent
  */
 public Scenario(MapEnvironment env, Map agentMap, string agentLoc)
 {
     this.agentMap     = agentMap;
     this.env          = env;
     this.initAgentLoc = agentLoc;
 }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Map"/> class.
 /// </summary>
 /// <param name="mapInfo"></param>
 /// <param name="mapEnvironment"></param>
 public Map(MapInfo mapInfo, MapEnvironment mapEnvironment)
 {
     Info        = mapInfo;
     Environment = mapEnvironment;
 }
示例#19
0
 public static void Write(this BinaryWriter writer, MapEnvironment mapEnvironment) => mapEnvironment.WriteTo(writer);
示例#20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Map"/> class.
 /// </summary>
 /// <param name="mapInfo"></param>
 /// <param name="mapEnvironment"></param>
 public Map(MapInfo mapInfo, MapEnvironment mapEnvironment)
 {
     Info        = mapInfo;
     Environment = mapEnvironment;
     Script      = string.Empty;
 }
示例#21
0
 public void SetDayButtonHandler(MapEnvironment env)
 {
     env.SetDay();
 }
示例#22
0
 public void SetNightButtonHandler(MapEnvironment env)
 {
     env.SetNight();
 }
示例#23
0
 public void StopTimeButtonHandler(MapEnvironment env)
 {
     env.StopTime();
 }
示例#24
0
 public void ToggleRainButtonHandler(MapEnvironment env)
 {
     env.ToggleRain();
 }