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); }
/** * 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); }
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); } } } } }
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)); } } }
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)); } } }