Ejemplo n.º 1
0
  public Price getMedianJudgedValue(int round) throws ScoreException {
    Quantity totalValue = Quantity.ZERO;
    int judgeCount = 0;
    for (Iterator iterator = playerNameIterator(); iterator.hasNext(); ) {
      Judge judge = getJudgeOrNull((String) iterator.next());
      if (judge == null || judge.isDormant(getCurrentRound())) {
        continue;
      }
      Price estimate = judge.getEstimate(round);
      if (estimate == null) {
        continue;
      }

      totalValue = totalValue.plus(estimate);
      judgeCount += 1;
    }
    if (judgeCount == 0) {
      if (cuttingOffJudges()) {
        return Price.dollarPrice(50);
      }
      String message =
          "Judges have not entered estimates for " + getRoundLabel() + " " + round + ".";
      appendToErrorMessage(message);
      throw new ScoreException(message);
    } else {
      return marketPrice(totalValue.div(judgeCount));
    }
  }
Ejemplo n.º 2
0
  private void setupCutoffTimers() {
    Logger cutoffLogger = sessionLogger();
    Random random = new Random();
    int cutoffIfSimultaneous = (int) (random.nextDouble() * (latestCutoff - earliestCutoff));
    if (simultaneousCutoff) {
      cutoffLogger.info("using a simultaneous cutoff of " + cutoffIfSimultaneous + " seconds.");
    }
    Iterator<String> nameIterator = playerNameIterator();
    while (nameIterator.hasNext()) {
      Judge judge = getJudgeOrNull(nameIterator.next());
      if (judge == null) {
        continue;
      }

      int cutoff;
      if (simultaneousCutoff) {
        cutoff = cutoffIfSimultaneous;
      } else {
        cutoff = earliestCutoff + (int) (random.nextDouble() * (latestCutoff - earliestCutoff));
        cutoffLogger.info(
            "using a cutoff for judge '" + judge.getName() + "' of " + cutoff + " seconds.");
        int roundDuration = timeLimit();
        if (cutoff > roundDuration + 10) {
          cutoff = roundDuration + 10;
          cutoffLogger.info(
              "reducing timeout to " + cutoff + " (10 seconds after round finishes).");
        }
      }
      TimerTask task = judge.getCutoffTimer();
      timer.schedule(task, 1000 * cutoff);
    }
  }
Ejemplo n.º 3
0
  @Override
  public Agent vote() {

    List<Agent> whiteAgent = new ArrayList<>();
    List<Agent> blackAgent = new ArrayList<>();

    for (Judge j : getMyJudgeList()) {
      if (getLatestDayGameInfo().getAliveAgentList().contains(judge.getTarget())) {
        switch (j.getResult()) {
          case HUMAN:
            whiteAgent.add(judge.getTarget());
            break;
          case WEREWOLF:
            blackAgent.add(judge.getTarget());
            break;
        }
      }
    }

    if (blackAgent.size() > 0) {
      return randomSelect(blackAgent);
    } else {
      List<Agent> voteCandidates = new ArrayList<Agent>();
      voteCandidates.addAll(getLatestDayGameInfo().getAliveAgentList());
      voteCandidates.remove(getMe());
      voteCandidates.removeAll(whiteAgent);

      return randomSelect(voteCandidates);
    }
  }
Ejemplo n.º 4
0
  // cancel all the timers
  void otherEndTradingEvents() {
    Iterator<String> nameIterator = playerNameIterator();
    while (nameIterator.hasNext()) {
      Judge judge = getJudgeOrNull(nameIterator.next());
      if (judge == null) {
        continue;
      }

      judge.cancelCutOffTimer();
    }
  }
Ejemplo n.º 5
0
  @Override
  public String talk() {
    if (!isComingout) {
      isComingout = true;
      String ret = TemplateTalkFactory.comingout(getMe(), getMyRole());
      return ret;
    }

    if (!tellMyJudge) {
      tellMyJudge = true;
      Judge judge = this.getLatestDayGameInfo().getDivineResult();
      if (judge != null) {
        String ret = TemplateTalkFactory.divined(judge.getTarget(), judge.getResult());
        return ret;
      }
    }

    return Talk.OVER;
  }
Ejemplo n.º 6
0
 public String getEstimatesHtml() {
   Session session = SessionSingleton.getSession();
   if (session == null) {
     return "";
   }
   Iterator iterator = session.playerNameSortedIterator();
   StringBuffer buff = new StringBuffer();
   printEstimatesTableHeader(session, buff);
   while (iterator.hasNext()) {
     String playerName = (String) iterator.next();
     Judge judge = getJudgeOrNull(playerName);
     if (null == judge) {
       continue;
     }
     HtmlRow.startTag(buff);
     buff.append(HtmlSimpleElement.printTableCell(playerName));
     judge.getGuessesRow(buff, session);
     HtmlRow.endTag(buff);
   }
   HtmlTable.endTagWithP(buff);
   return buff.toString();
 }
Ejemplo n.º 7
0
  @Override
  public Agent divine() {
    List<Agent> aliveAgentList = getLatestDayGameInfo().getAliveAgentList();
    aliveAgentList.remove(this.getMe());

    if (!isAgainstSeer) {
      return randomSelect(aliveAgentList);
    } else {
      double flag = Math.random();
      if (0.00D <= flag && flag < 0.05D) {
        List<Agent> againstSeer = new ArrayList<>();
        for (Agent agent : this.comingoutRole.keySet()) {
          Role role = this.comingoutRole.get(agent);
          if (role.equals(Role.SEER) && !agent.equals(this.getMe())) {
            againstSeer.add(agent);
          }
        }

        if (againstSeer.size() > 0) {
          return randomSelect(againstSeer);
        }
      } else if (0.05 <= flag && flag < 0.75D) {
        List<Agent> anotherDivinedAgent = new ArrayList();
        for (int i = 0; i < this.anotherJudgeList.size(); i++) {
          Judge judge = anotherJudgeList.get(i);
          if (!anotherDivinedAgent.contains(judge.getTarget())) {
            anotherDivinedAgent.add(judge.getTarget());
          }
        }

        if (anotherDivinedAgent.size() > 0) {
          return randomSelect(anotherDivinedAgent);
        }
      }

      return randomSelect(aliveAgentList);
    }
  }