Example #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));
    }
  }
Example #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);
    }
  }
Example #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);
    }
  }
Example #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();
    }
  }
Example #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;
  }
Example #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();
 }
Example #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);
    }
  }
Example #8
0
  // --------------------------------------------------------------------------
  // Constructor. If judge is null, it's to create a new judge.
  // --------------------------------------------------------------------------
  CreateJudgeScreen(JudgesPanel panel, Tournament t, Judge j) {
    jp = panel;
    tournament = t;
    judge = j;

    ScSS = new SchoolStrikesScreen(judge, tournament, this);
    StSS = new StudentStrikesScreen(judge, tournament, this);

    gbc = new GridBagConstraints();

    JLabel nameLabel = new JLabel("Last name:");
    nameField = new JTextField();
    nameField.setColumns(15);

    if (judge != null) nameField.setText(judge.getName());

    JLabel priorityLabel = new JLabel("Default priority:");
    priorityBox = new JComboBox(Priority.PriorityLevel.values());

    if (judge == null) priorityBox.setSelectedItem(Priority.PriorityLevel.Normal);
    else priorityBox.setSelectedItem(judge.getDefaultPriority());

    JButton schoolStrikes = new JButton("School strikes:");
    schoolStrikes.addActionListener(new SchoolStrikesListener());
    schoolStrikesLabel = new JLabel();
    resetSchoolStrikesLabel();

    JButton studentStrikes = new JButton("Student strikes:");
    studentStrikes.addActionListener(new StudentStrikesListener());
    studentStrikesLabel = new JLabel();
    resetStudentStrikesLabel();

    topPanel = new JPanel();
    topPanel.setLayout(new GridLayout(4, 2));

    topPanel.add(nameLabel);
    topPanel.add(nameField);
    topPanel.add(priorityLabel);
    topPanel.add(priorityBox);
    topPanel.add(schoolStrikes);
    topPanel.add(schoolStrikesLabel);
    topPanel.add(studentStrikes);
    topPanel.add(studentStrikesLabel);

    saveButton = new JButton("Save");
    saveButton.addActionListener(new SaveListener());
    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new CancelListener());
    deleteButton = new JButton("Delete");
    deleteButton.addActionListener(new DeleteListener());

    bottomPanel = new JPanel();
    bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));

    bottomPanel.add(saveButton);
    bottomPanel.add(cancelButton);
    bottomPanel.add(deleteButton);

    mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.add(topPanel);
    mainPanel.add(bottomPanel);

    scrollPane = new JScrollPane(mainPanel);
    add(scrollPane);
  }