Пример #1
0
        public void testAddUnknown()
        {
            // If nothing has been detected on the tile mark this as result. Estimates is empty and found is set
            AnalyzeMap map = new AnalyzeMap(1, 1);
            Tile tile = new Tile(0, 0);
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Nothing, Quality.Unknown) }));

            Assert.IsNull(map[tile].Estimates);
            Assert.IsNotNull(map[tile].Found);
            Assert.AreEqual(TileType.Nothing, map[tile].Found.Type);
        }
Пример #2
0
        public void testAdd()
        {
            // Setting a list of detected ores should set the estimates of the tile to exactly this list
            AnalyzeMap map = new AnalyzeMap(1, 1);
            Tile tile = new Tile(0, 0);
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Iron, Quality.Unknown), new Detected(TileType.Silver, Quality.Unknown) }));

            Assert.IsNotNull(map[tile].Estimates);
            Assert.AreEqual(2, map[tile].Estimates.Count);
            Assert.IsTrue(map[tile].Estimates.Contains(new Detected(TileType.Iron, Quality.Unknown)));
            Assert.IsTrue(map[tile].Estimates.Contains(new Detected(TileType.Silver, Quality.Unknown)));
        }
Пример #3
0
        public void NewMap()
        {
            gridControl1.GridSizeX = 16;
            gridControl1.GridSizeY = 16;

            map = new AnalyzeMap(gridControl1.GridSizeX, gridControl1.GridSizeY);
            map.OnResize += new AnalyzeMap.MapResizeHandler(map_OnResize);
            mapFileName = null;
            autoSaveFileName = null;
        }
Пример #4
0
 private void LoadMap(String filename)
 {
     using (Stream stream = new FileStream(filename, FileMode.Open))
     {
         this.map = AnalyzeMap.Load(stream);
         gridControl1.GridSizeX = map.SizeX;
         gridControl1.GridSizeY = map.SizeY;
         map.OnResize += new AnalyzeMap.MapResizeHandler(map_OnResize);
         mapFileName = filename;
         autoSaveFileName = null;
         activeTool = null;
         setCheckedTool(null);
     }
 }
Пример #5
0
 public override bool UseTool(AnalyzeMap map, Tile tile)
 {
     if (map[tile].Type != tileType)
     {
         map[tile].Type = tileType;
         return true;
     }
     return false;
 }
Пример #6
0
 public abstract bool UseTool(AnalyzeMap map, Tile tile);
Пример #7
0
        public static AnalyzeMap Load_1_2(XPathNavigator nav)
        {
            IXmlNamespaceResolver resolver = new MyNamespaceResolver();
            XPathNavigator root = nav.SelectSingleNode("//atm:AnalyzeMap", resolver);
            Double w = (Double) root.Evaluate("number(@width)");
            Double h = (Double) root.Evaluate("number(@height)");

            AnalyzeMap map = new AnalyzeMap((int)w, (int)h);

            XPathNodeIterator iter;
            iter = root.Select("atm:Tile", resolver);
            while (iter.MoveNext())
            {
                int x = (int)(Double)iter.Current.Evaluate("number(@x)");
                int y = (int)(Double)iter.Current.Evaluate("number(@y)");
                String type = (String)iter.Current.Evaluate("string(@type)");
                String quality = (String)iter.Current.Evaluate("string(@quality)");
                Boolean hasSalt = (Boolean)iter.Current.Evaluate("@salt = 'true'");
                Boolean hasFlint = (Boolean)iter.Current.Evaluate("@flint = 'true'");
                if (map.IsValidTile(x, y))
                {
                    map[x, y].Type = (TileType)Enum.Parse(typeof(TileType), type);
                    int exactQL;
                    if (quality != null && quality.Length != 0)
                    {
                        if (Int32.TryParse(quality, out exactQL))
                        {
                            map[x, y].ExactQuality = exactQL;
                        }
                        else
                        {
                            map[x, y].Quality = (Quality)Enum.Parse(typeof(Quality), quality);
                        }
                    }
                    if (hasSalt)
                        map[x, y].HasSalt = true;
                    if (hasFlint)
                        map[x, y].HasFlint = true;
                }
                else
                {
                    throw new Exception(String.Format("Tile {0},{1} is not valid for the map", x, y));
                }
            }

            iter = root.Select("atm:Analyze", resolver);
            while (iter.MoveNext())
            {
                int x = (int)(Double)iter.Current.Evaluate("number(@x)");
                int y = (int)(Double)iter.Current.Evaluate("number(@y)");

                List<AnalyzeMatch> matches = new List<AnalyzeMatch>();
                XPathNodeIterator entry = iter.Current.Select("atm:Entry", resolver);
                while (entry.MoveNext())
                {
                    String type = (String)entry.Current.Evaluate("string(@type)");
                    String quality = (String)entry.Current.Evaluate("string(@quality)");
                    String direction = (String)entry.Current.Evaluate("string(@direction)");
                    int distance = (int)(Double)entry.Current.Evaluate("number(@distance)");

                    if (type != null && type.Length == 0)
                        type = null;
                    if (quality != null && quality.Length == 0)
                        quality = null;
                    if (direction != null && direction.Length == 0)
                        direction = null;

                    matches.Add(new AnalyzeMatch(distance, type, quality, direction));
                }

                AnalyzeResult result = new AnalyzeResult(matches);
                result.X = x;
                result.Y = y;
                map.SetResult(x, y, result);
            }

            return map;
        }
Пример #8
0
        public void testTunnelFlint()
        {
            AnalyzeMap map = new AnalyzeMap(7, 7);
            AnalyzeResult result = new AnalyzeResult(new List<AnalyzeMatch>(new AnalyzeMatch[] { new AnalyzeMatch(3, "iron ore", "utmost", "west of north"), new AnalyzeMatch(3, "flint", null, "west of north"), new AnalyzeMatch(3, "salt", null, "west of north") }));
            map.SetResult(3, 3, result);

            Assert.IsNotNull(map[new Tile(1, 0)].Estimates);
            Assert.IsTrue(map[new Tile(1, 0)].Estimates.Contains(new Detected(TileType.Iron, Quality.Utmost)));
            Assert.IsTrue(map[new Tile(1, 0)].Estimates.Contains(new Detected(TileType.Flint, Quality.Unknown)));
            Assert.IsTrue(map[new Tile(1, 0)].Estimates.Contains(new Detected(TileType.Salt, Quality.Unknown)));
            Assert.IsNotNull(map[new Tile(2, 0)].Estimates);
            Assert.IsTrue(map[new Tile(2, 0)].Estimates.Contains(new Detected(TileType.Iron, Quality.Utmost)));
            Assert.IsTrue(map[new Tile(2, 0)].Estimates.Contains(new Detected(TileType.Flint, Quality.Unknown)));
            Assert.IsTrue(map[new Tile(2, 0)].Estimates.Contains(new Detected(TileType.Salt, Quality.Unknown)));

            map[new Tile(1, 0)].Set(new Detected(TileType.Tunnel, Quality.Unknown));
            Assert.IsNotNull(map[new Tile(1, 0)].Estimates);
            Assert.AreEqual(TileType.Tunnel, map[new Tile(1, 0)].Type);
            Assert.IsTrue(map[new Tile(1, 0)].Estimates.Contains(new Detected(TileType.Flint, Quality.Unknown)));
            Assert.IsTrue(map[new Tile(1, 0)].Estimates.Contains(new Detected(TileType.Salt, Quality.Unknown)));

            map.Refresh();

            Assert.IsNotNull(map[new Tile(2, 0)].Estimates);
            Assert.AreEqual(TileType.Iron, map[new Tile(2, 0)].Type);
            Assert.AreEqual(Quality.Utmost, map[new Tile(2, 0)].Quality);
            Assert.IsTrue(map[new Tile(2, 0)].Estimates.Contains(new Detected(TileType.Flint, Quality.Unknown)));
            Assert.IsTrue(map[new Tile(2, 0)].Estimates.Contains(new Detected(TileType.Salt, Quality.Unknown)));
            Assert.IsNotNull(map[new Tile(1, 0)].Estimates);
            Assert.AreEqual(TileType.Tunnel, map[new Tile(1, 0)].Type);
            Assert.IsTrue(map[new Tile(1, 0)].Estimates.Contains(new Detected(TileType.Flint, Quality.Unknown)));
            Assert.IsTrue(map[new Tile(1, 0)].Estimates.Contains(new Detected(TileType.Salt, Quality.Unknown)));
        }
Пример #9
0
        public void testSaltIronFlint()
        {
            AnalyzeMap map = new AnalyzeMap(3, 3);
            AnalyzeResult result = new AnalyzeResult(new List<AnalyzeMatch>(new AnalyzeMatch[] { new AnalyzeMatch(1, "iron ore", "utmost", "southeast"), new AnalyzeMatch(1, "salt", null, "southeast"), new AnalyzeMatch(1, "flint", null, "southeast") }));
            map.SetResult(1, 1, result);

            Tile tile = new Tile(2, 2);
            Assert.IsNull(map[tile].Estimates);
            Assert.IsNotNull(map[tile].Found);
            Assert.IsTrue(map[tile].HasSalt);
            Assert.IsTrue(map[tile].HasFlint);
            Assert.AreEqual(TileType.Iron, map[tile].Found.Type);
            Assert.AreEqual(Quality.Utmost, map[tile].Found.Quality);
            TileStatus status = map[tile];
            String text = status.ToString();
        }
Пример #10
0
        public void testSetSomething()
        {
            AnalyzeMap map = new AnalyzeMap(7, 7);
            AnalyzeResult result = new AnalyzeResult(new List<AnalyzeMatch>(new AnalyzeMatch[] { new AnalyzeMatch(3, "something", null, "northwest") }));
            map.SetResult(3, 3, result);

            Assert.IsNotNull(map[new Tile(0, 0)].Estimates);
            foreach (TileType tileType in resourceTypes)
            {
                Assert.IsTrue(map[new Tile(0, 0)].Estimates.Contains(new Detected(tileType, Quality.Unknown)), "Expected " + tileType);
            }
            foreach (TileType tileType in oreTypes)
            {
                Assert.IsTrue(map[new Tile(0, 0)].Estimates.Contains(new Detected(tileType, Quality.Unknown)), "Expected " + tileType);
            }
            Assert.IsNull(map[new Tile(0, 0)].Found);
        }
Пример #11
0
        public void testMergeUpdate()
        {
            // Setting Iron and Something (eg iron and silver) and adding Iron later on should leave only Iron
            AnalyzeMap map = new AnalyzeMap(1, 1);
            Tile tile = new Tile(0, 0);
            map[tile].Set(new Detected(TileType.Zinc, Quality.Unknown));

            Assert.IsNull(map[tile].Estimates);
            Assert.IsNotNull(map[tile].Found);
            Assert.AreEqual(TileType.Zinc, map[tile].Found.Type);
            Assert.AreEqual(Quality.Unknown, map[tile].Found.Quality);

            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Iron, Quality.Good), new Detected(TileType.Zinc, Quality.Good) }));

            Assert.IsNull(map[tile].Estimates);
            Assert.IsNotNull(map[tile].Found);
            Assert.AreEqual(TileType.Zinc, map[tile].Found.Type);
            Assert.AreEqual(Quality.Good, map[tile].Found.Quality);
        }
Пример #12
0
        public void testMergeUnknown()
        {
            // Setting Nothing and adding another detected ore should leave the tile at Nothing.
            AnalyzeMap map = new AnalyzeMap(1, 1);
            Tile tile = new Tile(0, 0);
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Nothing, Quality.Unknown) }));
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Iron, Quality.Good) }));

            Assert.IsNull(map[tile].Estimates);
            Assert.IsNotNull(map[tile].Found);
            Assert.AreEqual(TileType.Nothing, map[tile].Found.Type);
        }
Пример #13
0
        public void testMergeSomething()
        {
            // Setting Iron and Something (eg iron and silver) and adding Iron later on should leave only Iron
            AnalyzeMap map = new AnalyzeMap(1, 1);
            Tile tile = new Tile(0, 0);
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Iron, Quality.Unknown), new Detected(TileType.Something, Quality.Unknown) }));
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Iron, Quality.Good) }));

            Assert.IsNotNull(map[tile].Estimates);
            Assert.AreEqual(1, map[tile].Estimates.Count);
            Assert.IsTrue(map[tile].Estimates.Contains(new Detected(TileType.Iron, Quality.Good)));
        }
Пример #14
0
        public void testMergeComplex()
        {
            // Complex test
            // First "Something" is detected
            // Getting closer we detect "Iron, Zinc and something else
            // A 3rd analyze detects 2 iron of different quality and a zinc
            AnalyzeMap map = new AnalyzeMap(1, 1);
            Tile tile = new Tile(0, 0);
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Something, Quality.Unknown) }));
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Iron, Quality.Unknown), new Detected(TileType.Zinc, Quality.Unknown), new Detected(TileType.Something, Quality.Unknown) }));

            Assert.IsNotNull(map[tile].Estimates);
            Assert.AreEqual(11, map[tile].Estimates.Count);
            Assert.IsTrue(map[tile].Estimates.Contains(new Detected(TileType.Iron, Quality.Unknown)), "Does not contain Iron-Unknown");
            Assert.IsTrue(map[tile].Estimates.Contains(new Detected(TileType.Zinc, Quality.Unknown)), "Does not contain Zinc-Unknown");

            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Iron, Quality.Good), new Detected(TileType.Iron, Quality.Acceptable), new Detected(TileType.Zinc, Quality.Unknown) }));

            Assert.IsNotNull(map[tile].Estimates);
            Assert.AreEqual(3, map[tile].Estimates.Count);
            Assert.IsTrue(map[tile].Estimates.Contains(new Detected(TileType.Iron, Quality.Good)), "Does not contain Iron-Good");
            Assert.IsTrue(map[tile].Estimates.Contains(new Detected(TileType.Iron, Quality.Acceptable)), "Does not contain Iron-Acceptable");
            Assert.IsTrue(map[tile].Estimates.Contains(new Detected(TileType.Zinc, Quality.Unknown)), "Does not contain Zinc-Unknown");
        }
Пример #15
0
        public void testMerge()
        {
            // Setting a list of detected ores and adding another list should leave the union of the two lists
            AnalyzeMap map = new AnalyzeMap(1, 1);
            Tile tile = new Tile(0, 0);
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Iron, Quality.Unknown), new Detected(TileType.Silver, Quality.Unknown)}));
            map[tile].Add(new List<Detected>(new Detected[] { new Detected(TileType.Iron, Quality.Good) }));

            Assert.IsNotNull(map[tile].Estimates);
            Assert.AreEqual(1, map[tile].Estimates.Count);
            Assert.IsTrue(map[tile].Estimates.Contains(new Detected(TileType.Iron, Quality.Good)));
        }