@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof Player)) return false; Player other = (Player) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; }
@Override public Action doTurn(PlayerContext context) { PlayerId[][] field = context.getPlayField(); // Panic and shoot if (context.getBullets() > 0) { int distEnemy = VISION_WIDTH; int distZombie = VISION_WIDTH; PlayerId targetEnemy = null; PlayerId targetZombie = null; for (int x = CENTRE_OF_VISION - SHOOT_RANGE; x <= CENTRE_OF_VISION + SHOOT_RANGE; x++) { for (int y = CENTRE_OF_VISION - SHOOT_RANGE; y <= CENTRE_OF_VISION + SHOOT_RANGE; y++) { PlayerId player = field[x][y]; if (player != null && !killed.contains(player)) { int dist = getDistance(x, y); if (player.getName().equals("Zombie")) { if (dist < distZombie) { distZombie = dist; targetZombie = player; } } else if (isEnemy(player.getName()) && dist <= distEnemy) { distEnemy = dist; targetEnemy = field[x][y]; } } } } if (targetZombie != null && distZombie <= 3) { killed.add(targetZombie); return new Shoot(targetZombie); } else if (targetEnemy != null && distEnemy <= 5) { killed.add(targetEnemy); return new Shoot(targetEnemy); } } // Run away int bestScore = -10000000; Move bestMove = Move.randomMove(); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { PlayerId center = field[CENTRE_OF_VISION + x][CENTRE_OF_VISION + y]; if (center != null && !looted.contains(center) && center.getName().equals("DeadBody")) { looted.add(center); } if (center == null) { int thisScore = 0; for (int xx = CENTRE_OF_VISION + x - VISION_RANGE + 1; xx < CENTRE_OF_VISION + x + VISION_RANGE; xx++) { for (int yy = CENTRE_OF_VISION + y - VISION_RANGE + 1; yy < CENTRE_OF_VISION + y + VISION_RANGE; yy++) { PlayerId player = field[xx][yy]; if (player != null) { int dist = getDistance(xx - x, yy - y); if (player.getName().equals("Coward")) { // Prefer lose groups if (dist >= 3 && dist <= 6) { thisScore += 32; } else if (dist > 3) { thisScore += 16; } } else if (player.getName().equals("DeadBody")) { // Visit dead bodies on the route if (!looted.contains(player)) { thisScore += 32 * (VISION_RANGE - dist); } } else if (player.getName().equals("Zombie")) { // Avoid zombies if (dist <= 2) { thisScore -= 10000; } else if (dist <= 3) { thisScore -= 1000; } else if (dist <= 4) { thisScore -= 100; } } else if (isEnemy(player.getName())) { // Avoid strangers if (dist == 7) { thisScore -= 100; } else if (dist <= 6) { thisScore -= 1000; } } } } } if (thisScore > bestScore) { bestScore = thisScore; bestMove = Move.inDirection(x, y); } } } } return bestMove; }