private bool TryGetBestStepToItem(LevelView level, out Location locationToStep) { locationToStep = FindByDijkstra(level, IsToConsider, GetCost); return(locationToStep != default(Location)); bool IsToConsider(Location location) { level.Player.TryGetEquippedItem(out var item); return(level.GetItemAt(location).HasValue&& level.GetItemAt(location).AttackBonus > item.AttackBonus && level.GetItemAt(location).DefenceBonus > item.DefenceBonus); } int GetCost(Location location) { if (level.Field[location] == CellType.Wall || level.Field[location] == CellType.Trap || level.GetMonsterAt(location).HasValue) { return(100); } if (level.GetItemAt(location).HasValue) { level.Player.TryGetEquippedItem(out var item); if (level.GetItemAt(location).AttackBonus > item.AttackBonus && level.GetItemAt(location).DefenceBonus > item.DefenceBonus) { return(0); } return(100); } if (level.Field[location] == CellType.Exit) { return(0); } if (level.Field[location] == CellType.Empty || level.Field[location] == CellType.PlayerStart) { return(10 - GetNeighbours(location, NeighbourType.Eight) .Count(x => level.Field[x] == CellType.Trap || level.Field[x] == CellType.Wall)); } if (level.Field[location] == CellType.Hidden) { return(10); } throw new ArgumentOutOfRangeException(nameof(location)); } }
private static bool IsPassable(Location location, LevelView levelView) { var isObject = levelView.GetHealthPackAt(location).HasValue || levelView.GetMonsterAt(location).HasValue || levelView.GetItemAt(location).HasValue; var isEmpty = levelView.Field[location] == CellType.Empty || levelView.Field[location] == CellType.PlayerStart; return(!isObject && isEmpty); }
public static bool IsStepValid(this Location to, LevelView view) { if (to.X < 0 || to.X >= view.Field.Width || to.Y < 0 || to.Y >= view.Field.Height) { return(false); } return(view.Field[to] != CellType.Trap && view.Field[to] != CellType.Wall && view.Field[to] != CellType.Exit && !view.GetMonsterAt(to).HasValue && !view.GetItemAt(to).HasValue); }
private bool TryGetBestStepToHealth(LevelView level, out Location locationToStep) { locationToStep = FindByDijkstra(level, IsToConsider, GetCost); return(locationToStep != default(Location)); bool IsToConsider(Location location) { return(level.GetHealthPackAt(location).HasValue || location == _exit && _exit != default(Location) || GetNeighbours(location, NeighbourType.Four) .Any(y => level.Field[y] == CellType.Hidden && _hiddenYet.Contains(y))); } int GetCost(Location location) { if (level.Field[location] == CellType.Wall || level.Field[location] == CellType.Trap || level.GetMonsterAt(location).HasValue || level.GetItemAt(location).HasValue) { return(100); } if (level.Field[location] == CellType.Exit || level.GetHealthPackAt(location).HasValue) { return(0); } if (level.Field[location] == CellType.Empty || level.Field[location] == CellType.PlayerStart) { return(10 - GetNeighbours(location, NeighbourType.Eight) .Count(x => level.Field[x] == CellType.Trap || level.Field[x] == CellType.Wall)); } if (level.Field[location] == CellType.Hidden) { return(10); } throw new ArgumentOutOfRangeException(nameof(location)); } }