Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public void Reset()
 {
     this.Result       = null;
     this.Found        = null;
     this.TileEstimate = null;
     this.specialTypes = null;
 }
Ejemplo n.º 3
0
 public bool Matches(Detected d)
 {
     if (Type == TileType.Nothing || d.Type == TileType.Nothing)
     {
         return(Type == d.Type);
     }
     else if (Type == TileType.Something && IsOreType(d.Type))
     {
         return(true);
     }
     else if (d.Type == TileType.Something && IsOreType(Type))
     {
         return(true);
     }
     else if (Type == d.Type)
     {
         if (Quality != Quality.Unknown && d.Quality != Quality.Unknown)
         {
             return(Quality == d.Quality);
         }
         else
         {
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
        /**
         * Get the TileTypes which are covered by "Something".
         * Iron and Something effectively rules out Iron since it has been
         * detected on its own.
         */
        private HashSet <TileType> GetSomethingTypes(List <Detected> detected)
        {
            HashSet <TileType> types = new HashSet <TileType>();

            // Add all possible ore types
            foreach (TileType type in Enum.GetValues(typeof(TileType)))
            {
                if (Detected.IsOreType(type) && type != TileType.Something)
                {
                    types.Add(type);
                }
            }

            // Remove anything that has been detected already
            foreach (Detected d in detected)
            {
                TileType type = d.Type;
                if (Detected.IsOreType(type) && type != TileType.Something)
                {
                    types.Remove(type);
                }
            }

            return(types);
        }
Ejemplo n.º 5
0
        private HashSet <Detected> MakeSet(List <Detected> detected)
        {
            HashSet <Detected> set = new HashSet <Detected>(comparer);

            foreach (Detected d in detected)
            {
                if (d.Type == TileType.Nothing)
                {
                    continue;
                }
                else if (d.Type == TileType.Something)
                {
                    set.UnionWith(somethingTypes);
                }
                else if (Detected.IsOreType(d.Type))
                {
                    if (!set.Contains(d) || d.Quality != Quality.Unknown)
                    {
                        set.Remove(d);
                        set.Add(d);
                    }
                }
                else if (Detected.isSpecialType(d.Type))
                {
                    if (!set.Contains(d))
                    {
                        set.Add(d);
                    }
                }
            }
            return(set);
        }
Ejemplo n.º 6
0
 public TileStatus()
 {
     this.type         = TileType.Unknown;
     this.quality      = Quality.Unknown;
     this.Result       = null;
     this.Found        = null;
     this.TileEstimate = null;
 }
Ejemplo n.º 7
0
        private void SetDetected(int x, int y, int distance, List <Detected> detected)
        {
            foreach (Tile p in SelectTiles(x, y, distance))
            {
                Direction       dir         = GetTileDirection(p, x, y);
                List <Detected> dirDetected = FilterDetected(detected, dir);
                SetDetected(p.X, p.Y, dirDetected);
            }

            List <Tuple <Detected, List <Tile> > > matchesList = new List <Tuple <Detected, List <Tile> > >();

            foreach (Detected d in detected)
            {
                List <Tile> matches = new List <Tile>();
                foreach (Tile p in SelectTiles(x, y, distance))
                {
                    if (d.Direction != Direction.Unknown && d.Direction != GetTileDirection(p, x, y))
                    {
                        continue;
                    }
                    if (!IsValidTile(p.X, p.Y) || tileStatus[p.X, p.Y].Matches(d))
                    {
                        matches.Add(p);
                    }
                }
                matchesList.Add(new Tuple <Detected, List <Tile> >(d, matches));
            }

            foreach (Tuple <Detected, List <Tile> > tuple in matchesList)
            {
                Detected    d       = tuple.Item1;
                List <Tile> matches = tuple.Item2;
                if (matches.Count == 1)
                {
                    Tile p = matches[0];
                    if (IsValidTile(p.X, p.Y))
                    {
                        if (Detected.isSpecialType(d.Type))
                        {
                            tileStatus[p.X, p.Y].AddSpecial(d.Type);
                        }
                        else if (Detected.IsOreType(d.Type) && d.Type != TileType.Something)
                        {
                            Detected n = new Detected(d.Type, d.Quality);
                            if (n.Type == TileType.Something)
                            {
                                n.Type = tileStatus[p.X, p.Y].Type;
                            }
                            if (tileStatus[p.X, p.Y].Type == d.Type && d.Quality == Quality.Unknown)
                            {
                                n.Quality = tileStatus[p.X, p.Y].Quality;
                            }
                            tileStatus[p.X, p.Y].Set(n);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
 static TileEstimate()
 {
     foreach (TileType type in Enum.GetValues(typeof(TileType)))
     {
         if (Detected.IsOreType(type) && type != TileType.Something)
         {
             somethingTypes.Add(new Detected(type, Quality.Unknown));
         }
         else if (Detected.isSpecialType(type) && type != TileType.Something)
         {
             somethingTypes.Add(new Detected(type, Quality.Unknown));
         }
     }
 }
Ejemplo n.º 9
0
        public void testMatches()
        {
            foreach (TileType type in oreTypes)
            {
                Assert.IsTrue(Matches(type, type), "{0} matches {1}", type, type);
                Assert.IsTrue(Matches(type, TileType.Something), "{0} matches {1}", type, TileType.Something);
                Assert.IsTrue(Matches(TileType.Something, type), "{0} matches {1}", TileType.Something, type);
                Assert.IsFalse(Matches(type, TileType.Nothing), "{0} matches {1}", type, TileType.Nothing);
                Assert.IsFalse(Matches(TileType.Nothing, type), "{0} matches {1}", TileType.Nothing, type);
                Assert.IsTrue(Detected.IsOreType(type));

                foreach (TileType type2 in oreTypes)
                {
                    Assert.IsTrue(Matches(type, type2) == (type == type2));
                }

                foreach (TileType type2 in plainTypes)
                {
                    Assert.IsFalse(Matches(type, type2));
                }
            }

            foreach (TileType type in plainTypes)
            {
                Assert.IsTrue(Matches(type, type), "{0} matches {1}", type, type);
                Assert.IsFalse(Matches(type, TileType.Something), "{0} matches {1}", type, TileType.Something);
                Assert.IsFalse(Matches(TileType.Something, type), "{0} matches {1}", TileType.Something, type);
                Assert.IsFalse(Matches(type, TileType.Nothing), "{0} matches {1}", type, TileType.Nothing);
                Assert.IsFalse(Matches(TileType.Nothing, type), "{0} matches {1}", TileType.Nothing, type);
                Assert.IsFalse(Detected.IsOreType(type));

                foreach (TileType type2 in oreTypes)
                {
                    Assert.IsFalse(Matches(type, type2));
                }

                foreach (TileType type2 in plainTypes)
                {
                    Assert.IsTrue(Matches(type, type2) == (type == type2));
                }
            }
        }
Ejemplo n.º 10
0
 public bool Matches(Detected d)
 {
     if (Detected.isSpecialType(d.Type))
     {
         return(specialTypes == null || specialTypes.Contains(d.Type));
     }
     else if (Found != null)
     {
         return(Found.Matches(d));
     }
     else if (TileEstimate != null)
     {
         foreach (Detected e in TileEstimate.Estimates)
         {
             if (e.Matches(d))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 11
0
        private List <Detected> FilterDetected(List <Detected> detected, Direction dir)
        {
            int specialCount = 0;

            if (detected == null || detected.Count == 0 || dir == Direction.Unknown)
            {
                return(detected);
            }

            List <Detected> ret = new List <Detected>();

            foreach (Detected d in detected)
            {
                if (d.Direction == Direction.Unknown || d.Direction == dir)
                {
                    ret.Add(d);
                    if (Detected.isSpecialType(d.Type))
                    {
                        specialCount++;
                    }
                }
            }
            if (ret.Count == detected.Count)
            {
                return(detected);
            }
            else if (ret.Count == specialCount)
            {
                ret.Add(new Detected(TileType.Nothing, Quality.Unknown));
                return(ret);
            }
            else
            {
                return(ret);
            }
        }
Ejemplo n.º 12
0
 public void Set(Detected detected)
 {
     Found = new Detected(detected.Type, detected.Quality);
     if (TileEstimate != null)
     {
         List <Detected> list = new List <Detected>();
         foreach (Detected d in TileEstimate.Estimates)
         {
             if (Detected.isSpecialType(d.Type))
             {
                 list.Add(d);
             }
         }
         TileEstimate.Add(list);
         if (TileEstimate.Estimates.Count == 0)
         {
             TileEstimate = null;
         }
     }
     if (Found.Type != TileType.Nothing)
     {
         type = Found.Type;
     }
 }
Ejemplo n.º 13
0
 public TileStatus()
 {
     this.type = TileType.Unknown;
     this.quality = Quality.Unknown;
     this.Result = null;
     this.Found = null;
     this.TileEstimate = null;
 }
Ejemplo n.º 14
0
 public bool Matches(Detected d)
 {
     if (Type == TileType.Nothing || d.Type == TileType.Nothing)
     {
         return Type == d.Type;
     }
     else if (Type == TileType.Something && IsOreType(d.Type))
     {
         return true;
     }
     else if (d.Type == TileType.Something && IsOreType(Type))
     {
         return true;
     }
     else if (Type == d.Type)
     {
         if (Quality != Quality.Unknown && d.Quality != Quality.Unknown)
         {
             return Quality == d.Quality;
         }
         else
         {
             return true;
         }
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 15
0
        private void SetDetected(int x, int y, int distance, List<Detected> detected)
        {
            foreach (Tile p in SelectTiles(x, y, distance))
            {
                Direction dir = GetTileDirection(p, x, y);
                List<Detected> dirDetected = FilterDetected(detected, dir);
                SetDetected(p.X, p.Y, dirDetected);
            }

            List<Tuple<Detected, List<Tile>>> matchesList = new List<Tuple<Detected, List<Tile>>>();
            foreach (Detected d in detected)
            {
                List<Tile> matches = new List<Tile>();
                foreach (Tile p in SelectTiles(x, y, distance))
                {
                    if (d.Direction != Direction.Unknown && d.Direction != GetTileDirection(p, x, y))
                        continue;
                    if (!IsValidTile(p.X, p.Y) || tileStatus[p.X, p.Y].Matches(d))
                        matches.Add(p);
                }
                matchesList.Add(new Tuple<Detected,List<Tile>>(d, matches));
            }

            foreach (Tuple<Detected,List<Tile>> tuple in matchesList)
            {
                Detected d = tuple.Item1;
                List<Tile> matches = tuple.Item2;
                if (matches.Count == 1)
                {
                    Tile p = matches[0];
                    if (IsValidTile(p.X, p.Y))
                    {
                        if (Detected.isSpecialType(d.Type))
                        {
                            tileStatus[p.X, p.Y].AddSpecial(d.Type);
                        }
                        else if (Detected.IsOreType(d.Type) && d.Type != TileType.Something)
                        {
                            Detected n = new Detected(d.Type, d.Quality);
                            if (n.Type == TileType.Something)
                            {
                                n.Type = tileStatus[p.X, p.Y].Type;
                            }
                            if (tileStatus[p.X, p.Y].Type == d.Type && d.Quality == Quality.Unknown)
                            {
                                n.Quality = tileStatus[p.X, p.Y].Quality;
                            }
                            tileStatus[p.X, p.Y].Set(n);
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
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;
        }
Ejemplo n.º 17
0
 public void Set(Detected detected)
 {
     Found = new Detected(detected.Type, detected.Quality);
     if (TileEstimate != null)
     {
         List<Detected> list = new List<Detected>();
         foreach (Detected d in TileEstimate.Estimates)
         {
             if (Detected.isSpecialType(d.Type))
             {
                 list.Add(d);
             }
         }
         TileEstimate.Add(list);
         if (TileEstimate.Estimates.Count == 0)
         {
             TileEstimate = null;
         }
     }
     if (Found.Type != TileType.Nothing)
         type = Found.Type;
 }
Ejemplo n.º 18
0
 public void Reset()
 {
     this.Result = null;
     this.Found = null;
     this.TileEstimate = null;
     this.specialTypes = null;
 }
Ejemplo n.º 19
0
 public bool Matches(Detected d)
 {
     if (Detected.isSpecialType(d.Type))
     {
         return specialTypes == null || specialTypes.Contains(d.Type);
     }
     else if (Found != null)
     {
         return Found.Matches(d);
     }
     else if (TileEstimate != null)
     {
         foreach (Detected e in TileEstimate.Estimates)
         {
             if (e.Matches(d))
                 return true;
         }
     }
     return false;
 }