/// <summary> /// Moves the wumpus lowerBound-upperBound tiles away from its current location, both inclusive. /// </summary> /// <param name="lowerBound"></param> /// <param name="upperBound"></param> public void MoveAway(int lowerBound, int upperBound) { int oldLocation = Location; Random r = new Random(); //Order rooms randomly foreach (int i in Enumerable.Range(0, cave.RoomDict.Count).OrderBy(x => r.Next())) { KeyValuePair <int, Room> pair = cave.RoomDict.ElementAt(i); //Don't move the wumpus to a room with hazards if (pair.Value.HasBats || pair.Value.HasPit) { continue; } int?distance = cave.Distance(pair.Value, cave[oldLocation], true); if (distance.HasValue && distance.Value >= lowerBound && distance.Value <= upperBound) { Location = pair.Key; break; } } CurrentBehavior = ACTIVE_BEHAVIOR; Debug.Assert(oldLocation != Location); }
/// <summary> /// Initializes a new instance of the Wumpus class. /// </summary> /// <param name="map"></param> public Wumpus(Map map) { cave = map.Cave; this.map = map; ACTIVE_BEHAVIOR = new ActiveWumpusBehavior(this, map); PASSIVE_BEHAVIOR = new PassiveWumpusBehavior(this, map); CurrentBehavior = ACTIVE_BEHAVIOR; }