Example #1
0
 public static final void evaluate(final PlayerContext pc) {
   if (pc == null) {
     return;
   }
   final Profile profile = pc.profile;
   final Set<Integer> achieved = profile.achievements;
   final int size = ALL.length;
   boolean any = false;
   for (int i = 0; i < size; i++) {
     final Integer key = Integer.valueOf(i);
     if (achieved.contains(key)) {
       continue;
     }
     final Achievement ach = ALL[i];
     if (ach.isMet(pc)) {
       achieved.add(key);
       final int award = ach.award;
       FurGuardiansGame.notify(
           pc, ach.getName() + ", " + award + " Gem bonus", new Gem(FurGuardiansGame.gemAchieve));
       pc.addGems(award);
       any = true;
     }
   }
   if (any) {
     profile.save();
   }
 }
Example #2
0
  public void run() throws IOException {
    try {
      remoteProcessClient.writeToken(token);
      int teamSize = remoteProcessClient.readTeamSize();
      remoteProcessClient.writeProtocolVersion();
      Game game = remoteProcessClient.readGameContext();

      Strategy[] strategies = new Strategy[teamSize];

      for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) {
        strategies[strategyIndex] = new MyStrategy();
      }

      PlayerContext playerContext;

      while ((playerContext = remoteProcessClient.readPlayerContext()) != null) {
        Car[] playerCars = playerContext.getCars();
        if (playerCars == null || playerCars.length != teamSize) {
          break;
        }

        Move[] moves = new Move[teamSize];

        for (int carIndex = 0; carIndex < teamSize; ++carIndex) {
          Car playerCar = playerCars[carIndex];

          Move move = new Move();
          moves[carIndex] = move;
          strategies[playerCar.getTeammateIndex()].move(
              playerCar, playerContext.getWorld(), game, move);
        }

        remoteProcessClient.writeMoves(moves);
      }
    } finally {
      remoteProcessClient.close();
    }
  }
Example #3
0
  @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;
  }