Example #1
0
  private void printToGuiLog(PlayerState player, Transition action) {
    if (player.validLastTransition()) {
      if (action.operator == ActionType.PlayerReady) {
        Point2i initPos = GamePolicy.initialPlayerPositions.get(player.id);
        gui_logger.info(
            state.round.currentRound
                + " "
                + action.operator.name()
                + " "
                + player.id
                + " "
                + +initPos.x
                + " "
                + initPos.y
                + " "
                + player.getScore());

        for (UnitState u : player.units) {
          gui_logger.info(
              state.round.currentRound
                  + " "
                  + "UnitReady"
                  + " "
                  + player.id
                  + " "
                  + +u.id
                  + " "
                  + u.pos.x
                  + " "
                  + u.pos.y
                  + " "
                  + player.getScore()
                  + " "
                  + u.energy);
        }
      }
    }
  }
Example #2
0
  private void declareWinner() {
    // System.out.println("PRINTING RESULTS");

    class PlayerScore {
      public PlayerState player;
      public float score;

      public PlayerScore(PlayerState player, float score) {
        this.player = player;
        this.score = score;
      }

      public String toString() {
        return player.id.toString()
            + ","
            + score
            + ","
            + player.getKills()
            + ","
            + player.getRetaliationKills()
            + ","
            + player.getDeadUnits()
            + ","
            + player.getPlacedTowers()
            + ","
            + player.getSuccessfulTraps()
            + ","
            + player.getPlacedTraps()
            + ","
            + player.getKillingSprees()
            + ","
            + player.getFirstBlood();
      }
    }

    List<Integer> playerIDs = state.getPlayerIds();
    ArrayList<PlayerScore> scores = new ArrayList<PlayerScore>();

    for (Integer playerID : playerIDs) {
      PlayerState ps = state.playerStates.get(playerID);
      float score = ps.getScore();
      scores.add(new PlayerScore(ps, score));
    }

    Collections.sort(
        scores,
        new Comparator<PlayerScore>() {
          public int compare(PlayerScore a, PlayerScore b) {
            return Float.compare(b.score, a.score);
          }
        });

    try {
      BufferedWriter bw = new BufferedWriter(new FileWriter("winner.txt"));
      Iterator<PlayerScore> it = scores.iterator();
      logger.info("Scores:");
      while (it.hasNext()) {
        PlayerScore ps = it.next();
        bw.write(ps.toString());
        bw.newLine();
        logger.info(ps.toString());
      }
      bw.flush();
      bw.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }