Пример #1
0
  public Action choose(WumpusWorld.Hunter hunter, Set<Action> options) {
    System.out.format("%n%n");
    updateInternal(hunter);
    Room here = worldToPrivate.get(hunter.location());

    // check to see if we need to make a new decision
    if (decision != null && !decision.done(options)) {
      return decision.step(options);
    }

    // kill any adjacent, known wumpuses
    for (Room wumpus : here.adjacent) {
      if (wumpusKB.known(wumpus) && wumpusKB.evaluate(wumpus)) {
        System.out.println("DIE!");
        decision = new KillDecision(hunter, wumpus);
        return decision.step(options);
      }
    }

    // find any known wumpuses to kill
    for (Room wumpus : privateToWorld.keySet()) {
      if (wumpusKB.known(wumpus) && wumpusKB.evaluate(wumpus)) {
        Set<Room> safeRooms = safeRooms();
        safeRooms.add(wumpus);

        List<Room> path = path(here, wumpus, safeRooms);
        path.remove(wumpus);
        System.out.println("I've got it!");
        decision = new PathDecision(hunter, path);
        return decision.step(options);
      }
    }

    // find safe rooms to explore
    {
      System.out.println(safeRooms());
      List<Room> path = path(here, safeRooms());
      if (path != null) {
        System.out.println("Walking!");
        decision = new PathDecision(hunter, path);
        return decision.step(options);
      }
    }

    // find bats to exploit
    for (Room bat : privateToWorld.keySet()) {
      if (batKB.known(bat) && batKB.evaluate(bat)) {
        Set<Room> safeRooms = safeRooms();
        safeRooms.add(bat);
        System.out.println("Find a Bat!");
        List<Room> path = path(here, bat, safeRooms);
        return decision.step(options);
      }
    }

    // otherwise, take your 3 chances... they're only arrows!
    decision = new KillDecision(hunter, Groups.any(here.adjacent));
    return decision.step(options);
  }
Пример #2
0
    public Action step(Set<Action> options) {
      Room here = worldToPrivate.get(hunter.location());

      if (path == null || path.isEmpty()) {
        return null;
      }
      Room next = path.remove(0);
      return hunter.move(privateToWorld.get(next), options);
    }
Пример #3
0
  private void updateInternal(WumpusWorld.Hunter hunter) {
    // initialization (unknown -> start building internal representation)
    if (!worldToPrivate.containsKey(hunter.location())) {
      worldToPrivate.put(hunter.location(), new Room());
    }

    // update local information
    Room here = worldToPrivate.get(hunter.location());
    here.visited = true;

    wumpusKB.assign(here, false);
    batKB.assign(here, false);
    pitKB.assign(here, false);

    // update adjacent rooms
    for (Edge edge : hunter.location().edges) {
      if (!worldToPrivate.containsKey(edge.end)) {
        worldToPrivate.put(edge.end, new Room());
      }
      here.adjacent.add(worldToPrivate.get(edge.end));
      worldToPrivate.get(edge.end).adjacent.add(here);
    }

    // update knowledge base regarding adjacent rooms
    boolean rebuild = false;
    for (Room room : here.adjacent) {
      if (!hunter.scent() && wumpusKB.conflicts(room, false)) {
        rebuild = true;
      }
    }
    if (rebuild) {
      /*
      	BoolTable newWumpusKB = new BoolTable();
      	for(Room room : privateToWorld.keySet()) {
      		if(wumpusKB.known(room) && wumpusKB.evaluate(room) == false) {
      			newWumpusKB.assign(room, false);
      		}
      		if(!wumpusKB.known(room)) {
      			System.out.format("Suspicious Room: %s!%n", room);
      			for(Room adj : room.adjacent) {
      				System.out.format("   Resetting: %s!%n", adj);
      				room.visited = false;
      			}
      		}
      	}
      	wumpusKB = newWumpusKB;
      */
    }

    for (Room room : here.adjacent) {
      if (!hunter.scent()) {
        wumpusKB.assign(room, false);
      }
      if (!hunter.flapping()) {
        batKB.assign(room, false);
      }
      if (!hunter.wind()) {
        pitKB.assign(room, false);
      }
    }

    Map<Room, Boolean> possible = new HashMap<Room, Boolean>();
    for (Room room : here.adjacent) {
      possible.put(room, true);
    }
    if (hunter.scent()) {
      wumpusKB.assign(possible);
    }
    if (hunter.flapping()) {
      batKB.assign(possible);
    }
    if (hunter.wind()) {
      pitKB.assign(possible);
    }

    System.out.format("Wumpus KB : %s%n", wumpusKB);
    System.out.format("Bat KB    : %s%n", batKB);
    System.out.format("Pit KB    : %s%n", pitKB);
  }