public AbstractPokedex(Set<SeaLifePrototype> species) { map = Maps.newHashMap(); set = Sets.newHashSet(); for (SeaLifePrototype specie : species) { map.put(specie.getName(), new SeaLifePrototypeCounter(specie)); } }
private SeaLifePrototype getCreature(String creatureName) { for (SeaLifePrototype s : seaLifePossibilities) { if (creatureName == s.getName()) { return s; } } return null; }
public void creatureFulfilled(SeaLifePrototype creatureType) { PointOfInterest poi; for (Iterator<PointOfInterest> i = goals.iterator(); i.hasNext(); ) { poi = i.next(); if (poi.getCreature() == null) continue; if (poi.getCreature().getName().equals(creatureType.getName())) { i.remove(); } } }
/*Should only be called once*/ private void findDanger() { for (Observation o : whatYouSee) { // logger.trace("What I see: " + o.getName() + "\t\tIs it dangerous? " + o.isDangerous()); if (!o.isDangerous()) continue; Point2D predictedLocation; int speed = 0; int happy = 0; // can't use o.happiness() because that is 0 when you are on boat! for (SeaLifePrototype life : seaLifePossibilities) { if (life.getName().equals(o.getName())) { speed = life.getSpeed(); happy = life.getHappiness(); break; } } // Get the location and distance based on predicted location // (taking into account whether creature is stationary or moving). if (speed == 0 || o.getDirection() == null) { predictedLocation = o.getLocation(); } else { // predict where it will be Point2D loc = new Point2D.Double( // o.getLocation().getX() + (o.getDirection().getDx() * // (o.getDirection().isDiag() ? 3 : 2)), // o.getLocation().getY() + (o.getDirection().getDy() * // (o.getDirection().isDiag() ? 3 : 2)) o.getLocation().getX() + (o.getDirection().getDx()), o.getLocation().getY() + (o.getDirection().getDy())); if (ourBoard.inBounds((int) loc.getX(), (int) loc.getY())) { predictedLocation = loc; } else { predictedLocation = o.getLocation(); } } // For each Direction that diver can move, calculate the sum of danger from all creatures // affecting it. // The danger is scaled based on distance (decreases by a factor of radius). for (Direction d : Direction.values()) { Point2D nextPosition = new Point2D.Double(myPosition.getX() + d.getDx(), myPosition.getY() + d.getDy()); if (!ourBoard.inBounds((int) nextPosition.getX(), (int) nextPosition.getY())) continue; double distanceToCreature = Math.max(1.0, nextPosition.distance(predictedLocation)); // logger.debug("Direction:"+d+" distanceToCreature = " + distanceToCreature); // Only consider dangerous creatures if: // 1. They are stationary and affect cells next to the candidate cell, OR // 2. They are moving and affect cells within DANGER_MAX_DISTANCE of the candidate cell. if (o.isDangerous() && ((speed == 0 && distanceToCreature <= STATIONARY_DANGER_DISTANCE) || (speed > 0 && distanceToCreature <= DANGER_MAX_DISTANCE))) { double formerDirectionDanger = 0; if (directionDanger.containsKey(d)) { formerDirectionDanger = directionDanger.get(d); // logger.debug("formerDirectionDanger = " + formerDirectionDanger); } directionDanger.put( d, new Double( formerDirectionDanger + (Math.abs(happy * DANGER_MULTIPLIER) / Math.pow(distanceToCreature, 2)))); } } } }