Example #1
0
    public Action step(Set<Action> options) {
      count++;

      if (count == 1) {
        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;
      }
      if (count == 1) {
        return hunter.create(privateToWorld.get(target), WumpusWorld.Arrow.class, options);
      }

      return null;
    }
Example #2
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);
  }