Example #1
0
        private void gridControl1_DragDrop(object sender, DragEventArgs e)
        {
            Point pt = gridControl1.PointToClient(new Point(e.X, e.Y));

            System.Diagnostics.Debug.Print("DragDrop {0},{1}", pt.X, pt.Y);
            AnalyzeResult result = e.Data.GetData(typeof(AnalyzeResult)) as AnalyzeResult;

            if (result != null)
            {
                GridControl.Cell cell = gridControl1.CellFromPoint(pt.X, pt.Y);
                if (cell != null)
                {
                    map.SetResult(cell.X, cell.Y, result);
                    gridControl1.Redraw();
                }
            }
        }
Example #2
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);
        }
Example #3
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();
        }
Example #4
0
        public void testTunnel()
        {
            AnalyzeMap    map    = new AnalyzeMap(7, 7);
            AnalyzeResult result = new AnalyzeResult(new List <AnalyzeMatch>(new AnalyzeMatch[] { new AnalyzeMatch(3, "iron ore", "utmost", "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.IsNotNull(map[new Tile(2, 0)].Estimates);
            Assert.IsTrue(map[new Tile(2, 0)].Estimates.Contains(new Detected(TileType.Iron, Quality.Utmost)));

            map[new Tile(1, 0)].Set(new Detected(TileType.Tunnel, Quality.Unknown));
            map.SetResult(3, 3, result);

            Assert.IsNull(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.IsNull(map[new Tile(1, 0)].Estimates);
            Assert.AreEqual(TileType.Tunnel, map[new Tile(1, 0)].Type);
        }
Example #5
0
        public void SetResult(int x, int y, AnalyzeResult result)
        {
            if (tileStatus[x, y].Result != null && tileStatus[x, y].Result != result)
            {
                Remove(tileStatus[x, y].Result);
                Refresh();
            }
            if (results.Contains(result))
            {
                Remove(result);
                Refresh();
            }

            Dictionary <int, List <Detected> > matches = GetMatches(result);

            int maxDistance = matches.Keys.Max();

            if (x - maxDistance < 0 || y - maxDistance < 0 || x + maxDistance >= sizeX || y + maxDistance >= sizeY)
            {
                int dx   = Math.Max(0, maxDistance - x);
                int dy   = Math.Max(0, maxDistance - y);
                int newX = Math.Max(sizeX, x + maxDistance + 1);
                int newY = Math.Max(sizeY, y + maxDistance + 1);
                ResizeMap(newX + dx, newY + dy, dx, dy);

                x += dx;
                y += dy;
            }


            foreach (int distance in matches.Keys)
            {
                SetDetected(x, y, distance, matches[distance]);
            }

            tileStatus[x, y].Result = result;
            result.X = x;
            result.Y = y;
            results.Add(result);
        }
Example #6
0
 public void Remove(AnalyzeResult result)
 {
     if (results.Contains(result))
     {
         results.Remove(result);
         if (!result.PositionSet)
         {
             // Should not happen
             System.Diagnostics.Debug.Print("AnalyzeResult to be removed has no position set");
             Reset();
         }
         else if (tileStatus[result.X, result.Y].Result != result)
         {
             // Should not happen either
             System.Diagnostics.Debug.Print("AnalyzeResult to be removed is not where it's supposed to be");
             Reset();
         }
         else
         {
             // Reset all tiles that are affected by the Result
             tileStatus[result.X, result.Y].Result = null;
             Dictionary <int, List <Detected> > matches = GetMatches(result);
             foreach (int distance in matches.Keys)
             {
                 foreach (Tile p in SelectTiles(result.X, result.Y, distance))
                 {
                     tileStatus[p.X, p.Y].Reset();
                     if (tileStatus[p.X, p.Y].Type == TileType.Tunnel)
                     {
                         tileStatus[p.X, p.Y].Set(new Detected(TileType.Nothing, Quality.Unknown));
                     }
                 }
             }
         }
         Refresh();
     }
 }
Example #7
0
 private void AddResult(AnalyzeResult result)
 {
     if (resultsBox.InvokeRequired)
     {
         AddResultCallback d = new AddResultCallback(AddResult);
         this.Invoke(d, new object[] { result });
     }
     else
     {
         resultsBox.Items.Add(result);
         resultsBox.SelectedItem = result;
     }
 }
Example #8
0
        private Dictionary<int, List<Detected>> GetMatches(AnalyzeResult result)
        {
            Dictionary<int, List<Detected>> matches = new Dictionary<int, List<Detected>>();
            foreach (AnalyzeMatch match in result.Matches)
            {
                if (!matches.ContainsKey(match.Distance))
                    matches.Add(match.Distance, new List<Detected>());
                Detected detected = new Detected(GetTileType(match.Type), GetQuality(match.Quality), GetDirection(match.Direction));
                matches[match.Distance].Add(detected);
            }
            foreach (List<Detected> match in matches.Values)
            {
                int specialCount = 0;
                foreach (Detected d in match)
                {
                    if (Detected.isSpecialType(d.Type))
                    {
                        specialCount++;
                    }
                }
                if (match.Count == specialCount)
                {
                    match.Add(new Detected(TileType.Nothing, Quality.Unknown));
                }
            }

            return matches;
        }
Example #9
0
        public void SetResult(int x, int y, AnalyzeResult result)
        {
            if (tileStatus[x, y].Result != null && tileStatus[x, y].Result != result)
            {
                Remove(tileStatus[x, y].Result);
                Refresh();
            }
            if (results.Contains(result))
            {
                Remove(result);
                Refresh();
            }

            Dictionary<int, List<Detected>> matches = GetMatches(result);

            int maxDistance = matches.Keys.Max();
            if (x - maxDistance < 0 || y - maxDistance < 0 || x + maxDistance >= sizeX || y + maxDistance >= sizeY)
            {
                int dx = Math.Max(0, maxDistance - x);
                int dy = Math.Max(0, maxDistance - y);
                int newX = Math.Max(sizeX, x + maxDistance + 1);
                int newY = Math.Max(sizeY, y + maxDistance + 1);
                ResizeMap(newX + dx, newY + dy, dx, dy);

                x += dx;
                y += dy;
            }

            foreach (int distance in matches.Keys)
            {
                SetDetected(x, y, distance, matches[distance]);
            }

            tileStatus[x, y].Result = result;
            result.X = x;
            result.Y = y;
            results.Add(result);
        }
Example #10
0
 public void Remove(AnalyzeResult result)
 {
     if (results.Contains(result))
     {
         results.Remove(result);
         if (!result.PositionSet)
         {
             // Should not happen
             System.Diagnostics.Debug.Print("AnalyzeResult to be removed has no position set");
             Reset();
         }
         else if (tileStatus[result.X, result.Y].Result != result)
         {
             // Should not happen either
             System.Diagnostics.Debug.Print("AnalyzeResult to be removed is not where it's supposed to be");
             Reset();
         }
         else
         {
             // Reset all tiles that are affected by the Result
             tileStatus[result.X, result.Y].Result = null;
             Dictionary<int, List<Detected>> matches = GetMatches(result);
             foreach (int distance in matches.Keys)
             {
                 foreach (Tile p in SelectTiles(result.X, result.Y, distance))
                 {
                     tileStatus[p.X, p.Y].Reset();
                     if (tileStatus[p.X, p.Y].Type == TileType.Tunnel)
                         tileStatus[p.X, p.Y].Set(new Detected(TileType.Nothing, Quality.Unknown));
                 }
             }
         }
         Refresh();
     }
 }
Example #11
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;
        }
Example #12
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)));
        }
Example #13
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);
        }
Example #14
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();
        }
Example #15
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);
        }