@Test
  public void testHandDouble() {
    PlayingStrategy playingStrategy = new PlayingStrategyFixed(Round.Offer.DOUBLE, MONEY_1, false);
    Game game = new Game(playingStrategy, 1, MONEY_10);
    Deck deck = new MockDeck(Rank.THREE, Rank.TEN, Rank.TEN, Rank.TWO, Rank.EIGHT);
    game.setDeck(deck);
    playGameWrapException(game);
    Round round = game.getLastRound();
    Hand hand = round.getHand(1);
    Hand dealerHand = round.getDealerHand();

    // dealing of cards
    assertEquals(hand, HandTest.toHand(Rank.THREE, Rank.TEN, Rank.TWO));
    assertEquals(dealerHand, HandTest.toHand(Rank.TEN, Rank.EIGHT));

    // calculation of points
    assertEquals(hand.getFinalPoints().intValue(), 15);
    assertEquals(dealerHand.getFinalPoints().intValue(), 18);

    // status changes
    assertEquals(hand.getHandOutcome(), Hand.HandOutcome.LOSS);
    assertEquals(hand.getInsuranceOutcome(), Hand.InsuranceOutcome.NOT_OFFERED);

    // money adjustment
    assertEquals(round.getMoneyStart(), MONEY_10);
    assertEquals(round.getMoneyEnd(), MONEY_8);
    assertEquals(game.getMoneyStart(), MONEY_10);
    assertEquals(game.getMoneyCurrent(), MONEY_8);
  }
  public CSV(Tournament t, Round r) {
    properties = TournamentProperties.getProperties();
    separator = ";" + System.getProperty("line.separator");
    logLocation = properties.getProperty("logLocation");
    baseUrl = properties.getProperty("actionIndex.logUrl", "download?game=%d");
    baseUrl = baseUrl.substring(0, baseUrl.lastIndexOf("game"));

    if (t != null) {
      String name = "%stournament.%s.csv";
      String levels = "%srounds.%s.csv";
      names =
          new String[] {
            String.format(name, logLocation, t.getTournamentName().replaceAll(" ", "_")),
            String.format(name, logLocation, t.getTournamentId()),
            String.format(levels, logLocation, t.getTournamentName().replaceAll(" ", "_")),
            String.format(levels, logLocation, t.getTournamentId())
          };
    } else if (r != null) {
      String name = "%sround.%s.csv";
      String games = "%sgames.%s.csv";
      names =
          new String[] {
            String.format(name, logLocation, r.getRoundName().replaceAll(" ", "_")),
            String.format(name, logLocation, r.getRoundId()),
            String.format(games, logLocation, r.getRoundName().replaceAll(" ", "_")),
            String.format(games, logLocation, r.getRoundId())
          };
    }
  }
示例#3
0
  public static void main(String[] args) {

    List<Card> cards = new LinkedList<Card>();
    for (Value v : Value.values()) {
      for (Suit s : Suit.values()) {
        cards.add(new Card(v, s));
      }
    }

    Random rand = new Random();
    Card[] cards1 = new Card[7];
    Card[] cards2 = new Card[7];

    for (int i = 0; i < 7; i++) {
      // Card c = cards.remove(rand.nextInt(cards.size())) ;
      Card c1 = cards.remove(2 + i * 3);
      cards1[i] = c1;
      Card c2 = cards.remove(rand.nextInt(cards.size()));
      cards2[i] = c2;
    }

    System.out.println("------ Card 1 ---------");
    for (Card c : cards1) {
      System.out.println(c.getSuit() + " " + c.getValue());
    }
    System.out.println(Round.getRank(cards1));
    System.out.println("------ Card 2 ---------");
    for (Card c : cards2) {
      System.out.println(c.getSuit() + " " + c.getValue());
    }
    System.out.println(Round.getRank(cards2));
  }
  private void gamesCsv(Round round) {
    File gamesCSV = new File(names[2]);

    if (gamesCSV.isFile() && gamesCSV.canRead()) {
      gamesCSV.delete();
    }

    if (round.getSize() == 0) {
      return;
    }

    try {
      gamesCSV.createNewFile();

      FileWriter fw = new FileWriter(gamesCSV.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      bw.write(
          "gameId;gameName;status;gameSize;gameLength;lastTick;"
              + "weatherLocation;weatherDate;logUrl;brokerId;brokerBalance;"
              + separator);

      String tourneyUrl = properties.getProperty("tourneyUrl");
      String baseUrl = properties.getProperty("actionIndex.logUrl", "download?game=%d");
      for (Game game : round.getGameMap().values()) {
        String logUrl = "";
        if (game.isComplete()) {
          if (baseUrl.startsWith("http://")) {
            logUrl = String.format(baseUrl, game.getGameId());
          } else {
            logUrl = tourneyUrl + String.format(baseUrl, game.getGameId());
          }
        }

        String content =
            String.format(
                "%d;%s;%s;%d;%d;%d;%s;%s;%s;",
                game.getGameId(),
                game.getGameName(),
                game.getState(),
                game.getSize(),
                game.getGameLength(),
                game.getLastTick(),
                game.getLocation(),
                game.getSimStartTime(),
                logUrl);
        for (Agent agent : game.getAgentMap().values()) {
          content = String.format("%s%d;%f;", content, agent.getBrokerId(), agent.getBalance());
        }

        bw.write(content + separator);
      }

      bw.close();

      copyFile(gamesCSV, names[3]);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  @Test
  public void testInsuranceWinGameLose() {
    PlayingStrategy playingStrategy = new PlayingStrategyFixed(Round.Offer.STAND, MONEY_1, true);
    Game game = new Game(playingStrategy, 1, MONEY_10);
    Deck deck = new MockDeck(Rank.THREE, Rank.TEN, Rank.ACE, Rank.JACK);
    game.setDeck(deck);
    playGameWrapException(game);
    Round round = game.getLastRound();
    Hand hand = round.getHand(1);
    Hand dealerHand = round.getDealerHand();

    // dealing of cards
    assertEquals(hand, HandTest.toHand(Rank.THREE, Rank.TEN));
    assertEquals(dealerHand, HandTest.toHand(Rank.ACE, Rank.JACK));

    // calculation of points
    assertEquals(hand.getFinalPoints().intValue(), 13);
    assertEquals(dealerHand.getFinalPoints().intValue(), 21);

    // status changes
    assertEquals(hand.getHandOutcome(), Hand.HandOutcome.LOSS);
    assertEquals(hand.getInsuranceOutcome(), Hand.InsuranceOutcome.WIN);

    // money adjustment
    assertEquals(round.getMoneyStart(), MONEY_10);
    assertEquals(round.getMoneyEnd(), MONEY_10);
    assertEquals(game.getMoneyStart(), MONEY_10);
    assertEquals(game.getMoneyCurrent(), MONEY_10);
  }
示例#6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    Intent i = getIntent();

    // initialize variables from intent
    tournament = (Tournament) i.getSerializableExtra("Tournament");
    round = (Round) i.getSerializableExtra("Round");
    teamList = round.getTeamList();
    winningTeamList = round.getRoundWinners();
    currentRoundIndex = round.getRoundNumber();
    nextRoundIndex = currentRoundIndex + 1;
    numOfRounds = tournament.getNumberOfRounds();

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_results);

    if (currentRoundIndex == numOfRounds - 1) {

      Button btn = (Button) findViewById(R.id.buttonContinue);
      btn.setText("View stats");
    }

    populateListView();
  }
  private void levelsCsv(Tournament tournament) {
    File levelsCSV = new File(names[2]);

    if (levelsCSV.isFile() && levelsCSV.canRead()) {
      levelsCSV.delete();
    }

    try {
      levelsCSV.createNewFile();

      FileWriter fw = new FileWriter(levelsCSV.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      for (Level level : tournament.getLevelMap().values()) {
        bw.write("levelId;" + level.getLevelId() + separator);
        bw.write("levelName;" + level.getLevelName() + separator);
        bw.write("levelNr;" + level.getLevelNr() + separator);
        bw.write("nofWinners;" + level.getNofWinners() + separator);
        bw.write("startTime;" + Utils.dateToStringFull(level.getStartTime()) + separator);
        bw.write(separator);
        for (Round round : level.getRoundMap().values()) {
          Map<Broker, double[]> resultMap = round.determineWinner();
          singleRound(bw, ";", round, resultMap);
          bw.write(separator);
        }
      }

      bw.close();

      copyFile(levelsCSV, names[3]);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#8
0
  public void execute(TextUI textUI) {
    this.initializePlayers();
    this.dealCards();
    for (Round round : this.rounds) {
      round.execute(textUI, this.firstPlayer, this.players);
    }
    String score = "";
    // Transfer temporary menhirs in 'menhirsMatch' to 'menhirs'
    for (Player p : this.players) {
      p.setMenhirs(p.getMenhirs() + p.getMenhirsMatch());
      p.setMenhirsMatch(0);
    }
    // Sort players to display by score
    Collections.sort(this.players);

    for (Player p : this.players) {
      score += p.finalScoreToString() + "\n";
    }
    textUI.showMessage(score);
    // Re-sort players to have initial order by ID (very important)
    Collections.sort(this.players, Player.Comparators.ID);

    // Reset stones
    for (Player p : this.players) {
      p.setStones(0);
    }
  }
 @Transient
 public int getNofBrokers() {
   int nofBrokers = 0;
   for (Round round : levelMap.get(0).getRoundMap().values()) {
     nofBrokers += round.getBrokerMap().size();
   }
   return nofBrokers;
 }
  @Transient
  public boolean isStarted() {
    Level firstLevel = levelMap.get(0);

    for (Round round : firstLevel.getRoundMap().values()) {
      if (round.isStarted()) {
        return true;
      }
    }
    return false;
  }
示例#11
0
  /**
   * Return the score.
   *
   * @return the score
   */
  public int getScore() {
    int scores = 0;
    Round bowlingRoundCurrent = bowlingFirstRound;
    scores += bowlingRoundCurrent.getScoreRound();
    while (bowlingRoundCurrent.getNextRound() != null) {
      bowlingRoundCurrent = bowlingRoundCurrent.getNextRound();
      scores += bowlingRoundCurrent.getScoreRound();
    }

    return scores;
  }
示例#12
0
  public void run() {

    int money = round.askMoneyToBet();
    // player.setCurrentMoney(money);

    round.playRound();

    System.out.println("You are broke after " + round.getCounter() + " rolls.");
    System.out.println(
        "You should have quit after "
            + round.getCounterAtMaxMoney()
            + " rolls when you had $"
            + player.getMaxMoney());
  }
示例#13
0
  /**
   * Tests that the game starts and stops properly given the number of rounds requested and money
   * available
   */
  @Test
  public void testNumRounds() {
    // test number of rounds played (1 round)
    PlayingStrategy playingStrategy = new PlayingStrategyFixed(Round.Offer.STAND, MONEY_1, false);
    Game game = new Game(playingStrategy, 1, MONEY_10);
    playGameWrapException(game);
    assertEquals(game.getNumRoundsPlayed(), 1);
    assertEquals(game.getNumRoundsToPlay(), 1);
    assertEquals(game.getPastRounds().size(), 1);
    assertEquals(game.isUserInputNeeded(), false);
    assertEquals(game.isFinished(), true);
    assertNull(game.getCurrentRound());
    Round round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);

    // test number of rounds played (5 rounds)
    playingStrategy = new PlayingStrategyFixed(Round.Offer.STAND, MONEY_1, false);
    game = new Game(playingStrategy, 5, MONEY_10);
    playGameWrapException(game);
    assertEquals(game.getNumRoundsPlayed(), 5);
    assertEquals(game.getNumRoundsToPlay(), 5);
    assertEquals(game.getPastRounds().size(), 5);
    assertEquals(game.isUserInputNeeded(), false);
    assertEquals(game.isFinished(), true);
    assertNull(game.getCurrentRound());
    round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);

    // test number of rounds played (money runs out)
    playingStrategy = new PlayingStrategyFixed(Round.Offer.HIT, MONEY_1, false);
    game = new Game(playingStrategy, 20, MONEY_10);
    game.setDeck(
        new MockDeckFixed(
            Rank.TEN)); // by getting only 10s and hitting each time will definitely lose
    playGameWrapException(game);
    assertEquals(game.getNumRoundsPlayed(), 10);
    assertEquals(game.getNumRoundsToPlay(), 20);
    assertEquals(game.getPastRounds().size(), 10);
    assertEquals(game.isUserInputNeeded(), false);
    assertEquals(game.isFinished(), true);
    assertNull(game.getCurrentRound());
    round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);
  }
  private void roundCsv(Round round) {
    File roundCSV = new File(names[0]);

    if (roundCSV.isFile() && roundCSV.canRead()) {
      roundCSV.delete();
    }

    Map<Broker, double[]> resultMap = round.determineWinner();
    if (resultMap.size() == 0) {
      return;
    }

    // Create new CSVs
    try {
      roundCSV.createNewFile();

      FileWriter fw = new FileWriter(roundCSV.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      singleRound(bw, "", round, resultMap);

      bw.close();

      copyFile(roundCSV, names[1]);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#15
0
  public final Match start() {
    Random rnd = new Random();
    this.stated = Calendar.getInstance();

    /* Criando lista de armas disponiveis para o Round*/
    ListObjects<Weapon> weapons = SimuladorDados.criandoListaArmas();

    /* Partidas são iniciadas para todos, porém so podem jogar quem aceitar o Round*/
    ListObjects<Player> players = SimuladorDados.criandoJogadores();
    for (int i = 0; i < 5; i++) {
        /*simulando 10 Rounds*/

      /*Cada jogador começa o partida com R$ 1000.
       * Cada morte quanha R$ 450 e cada vez que morre perde R$ 100*/
      GameMap gameMap = gameMaps.get(rnd.nextInt(gameMaps.size()));
      Round rd = Round.newRound(gameMap, players, weapons);
      new SimuladorDados<Round>() {

        @Override
        protected void terminate(Round rd) {
          rounds.add(rd);
        }
      }.start(logApps, rd);
      this.ended = Calendar.getInstance();
    }
    terminate((ROUND) rounds, (WEAPONS) weapons, (PLAYERS) players);
    return this;
  }
    /** Create a new round. */
    private Round(
        Round prev, Set<JavaFileObject> newSourceFiles, Map<String, JavaFileObject> newClassFiles) {
      this(prev.nextContext(), prev.number + 1, prev.nMessagerErrors, prev.compiler.log.nwarnings);
      this.genClassFiles = prev.genClassFiles;

      List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles);
      roots = cleanTrees(prev.roots).appendList(parsedFiles);

      // Check for errors after parsing
      if (unrecoverableError()) return;

      enterClassFiles(genClassFiles);
      List<ClassSymbol> newClasses = enterClassFiles(newClassFiles);
      genClassFiles.putAll(newClassFiles);
      enterTrees(roots);

      if (unrecoverableError()) return;

      topLevelClasses =
          join(getTopLevelClasses(parsedFiles), getTopLevelClassesFromClasses(newClasses));

      packageInfoFiles =
          join(getPackageInfoFiles(parsedFiles), getPackageInfoFilesFromClasses(newClasses));

      findAnnotationsPresent();
    }
示例#17
0
  // populate the results with the game scores of this tournament
  public void populateListView() {

    ArrayAdapter<String> adapter =
        new ArrayAdapter(this, android.R.layout.select_dialog_item, round.getGameScoreList());
    ListView listview = (ListView) findViewById(R.id.gamesList);
    listview.setAdapter(adapter);
  }
示例#18
0
 /**
  * Returns the winner of this game.
  *
  * @return the winner of this game or <code>null</code> if there is no winner.
  */
 public Player getWinner() {
   Player winner = null;
   Round lastRound = this.getLastRound();
   if (lastRound == null) {
     return winner;
   }
   int correct = GameConfiguration.numberLength();
   for (Player player : lastRound.getAnswers().keySet()) {
     Answer answer = lastRound.getAnswers().get(player);
     if (answer.getCorrect() == correct) {
       winner = player;
       break;
     }
   }
   return winner;
 }
  public static Game createGame(Round round, int counter) {
    String gameName =
        String.format("%s_%d", round.getLevel().getTournament().getTournamentName(), counter);

    Game game = new Game();
    game.setGameName(gameName);
    game.setRound(round);
    game.setState(GameState.boot_pending);
    game.setStartTime(round.getStartTime());
    game.setLocation(randomLocation(round));
    game.setSimStartTime(randomSimStartTime(game.getLocation()));
    game.setServerQueue(Utils.createQueueName());
    game.setVisualizerQueue(Utils.createQueueName());

    return game;
  }
示例#20
0
 public void add(Round round) {
   if (pointsmap.isEmpty()) {
     for (Trackpoint tp : round.getPoints()) {
       Point point = new Point(tp.getLat(), tp.getLon());
       points.add(point);
       pointsmap.put(tp, point);
     }
   }
 }
示例#21
0
 /**
  * Plays the given round (this is used to load/replay)
  *
  * @param board The board
  * @param round The round to do
  */
 public void play(ABoard board, Round round) {
   switch (round.getType()) {
     case MOVE:
       board.move(num, round.getCoord());
       break;
     case WALL:
       board.setWall(round.getCoord());
       wallCounter--;
       break;
     case DEST:
       board.destroyWall(round.getCoord());
       waitingTurns++;
       break;
     case NONE:
       if (waitingTurns > 0) waitingTurns--;
       break;
   }
 }
示例#22
0
  /**
   * Makes a guess.
   *
   * @param player the player making the guess.
   * @param guess the guess to make.
   * @return the next step in the current game.
   * @throws GameException if the guess cannot be made.
   */
  public GameStep guess(Player player, Number guess) throws GameException {
    GameStep gs = new GameStep(GameStep.Type.GUESS, player);
    this.checkStep(gs, this.gameStep);

    Round r = this.getLastRound();
    if (r != null) {
      Map<Player, Number> guesses = r.getGuesses();
      if (r.getGuesses().containsKey(player)) {
        if (this.players.size() == guesses.size()) {
          r = new Round();
          this.rounds.add(r);
        } else {
          throw new GameException(String.format("%s has already made a guess this round", player));
        }
      }
    } else {
      r = new Round();
      this.rounds.add(r);
    }

    int playerIndex = this.players.indexOf(player);
    int opponentIndex = playerIndex + 1;
    if (opponentIndex == this.players.size()) {
      opponentIndex = 0;
    }
    Player opponent = this.players.get(opponentIndex);

    r.addGuess(player, opponent, guess);

    if (this.isGameOver()) {
      this.gameStep = new GameStep(GameStep.Type.GAME_OVER);
    } else {
      Player nextPlayer = null;
      if (playerIndex == this.players.size() - 1) {
        nextPlayer = this.players.get(0);
      } else {
        nextPlayer = this.players.get(playerIndex + 1);
      }
      this.gameStep = new GameStep(GameStep.Type.GUESS, nextPlayer);
    }

    return this.gameStep;
  }
示例#23
0
 public Outcome throwDice(int[] dice) {
   dice[0] = random.nextInt(6) + 1;
   dice[1] = random.nextInt(6) + 1;
   round.addNumber(dice[0], dice[1]);
   Outcome outcome = Outcome.CAN_ROLL;
   if (dice[0] == 1 && dice[1] == 1) {
     resetRounds();
     round.resetCounts();
     nextRound();
     outcome = Outcome.CANT_ROLL;
   }
   if (dice[0] == 1 || dice[1] == 1) {
     round.resetCounts();
     nextRound();
     outcome = Outcome.CANT_ROLL;
   }
   if ((dice[0] == dice[1]) && dice[0] != 1) {
     outcome = Outcome.MUST_ROLL;
   }
   return outcome;
 }
  // Computes a random game length as outlined in the game specification
  public int computeGameLength() {
    String p = round.getRoundName().toLowerCase().contains("test") ? "test" : "competition";
    int minLength = properties.getPropertyInt(p + ".minimumTimeslotCount");
    int expLength = properties.getPropertyInt(p + ".expectedTimeslotCount");

    if (expLength == minLength) {
      return minLength;
    } else {
      double roll = random.nextDouble();
      // compute k = ln(1-roll)/ln(1-p) where p = 1/(exp-min)
      double k = (Math.log(1.0 - roll) / Math.log(1.0 - 1.0 / (expLength - minLength + 1)));
      return minLength + (int) Math.floor(k);
    }
  }
示例#25
0
  @Test
  public void testHandSplit() {
    PlayingStrategy playingStrategy = new PlayingStrategyInteractive();
    Game game = new Game(playingStrategy, 1, MONEY_10);
    Deck deck = new MockDeck(Rank.THREE, Rank.THREE, Rank.TEN, Rank.TWO, Rank.EIGHT, Rank.SEVEN);
    game.setDeck(deck);

    playGameWrapException(game);
    playingStrategy.setAmountBet(MONEY_1);
    playGameWrapException(game);
    playingStrategy.setResponseToOffer(Offer.SPLIT);
    playGameWrapException(game);
    playingStrategy.setResponseToOffer(Offer.STAND);
    playGameWrapException(game);
    playingStrategy.setResponseToOffer(Offer.STAND);

    Round round = game.getLastRound();
    Hand hand1 = round.getHand(1);
    Hand hand2 = round.getHand(2);
    Hand dealerHand = round.getDealerHand();

    // dealing of cards
    assertEquals(hand1, HandTest.toHand(Rank.THREE, Rank.TWO));
    assertEquals(hand2, HandTest.toHand(Rank.THREE, Rank.EIGHT));
    assertEquals(dealerHand, HandTest.toHand(Rank.TEN, Rank.SEVEN));

    // status changes
    assertEquals(hand1.getHandOutcome(), Hand.HandOutcome.LOSS);
    assertEquals(hand2.getHandOutcome(), Hand.HandOutcome.LOSS);

    // money adjustment
    assertEquals(round.getMoneyStart(), MONEY_10);
    assertEquals(round.getMoneyEnd(), MONEY_8);
    assertEquals(game.getMoneyStart(), MONEY_10);
    assertEquals(game.getMoneyCurrent(), MONEY_8);
  }
示例#26
0
  /** Tests that the interactive strategy properly stops and waits for input and then continues */
  @Test
  public void testGameInteractive() {
    // test number of rounds played (1 round)
    PlayingStrategy playingStrategy = new PlayingStrategyInteractive();
    Game game = new Game(playingStrategy, 1, MONEY_10);
    playGameWrapException(game);
    game.setDeck(
        new MockDeckFixed(
            Rank.TEN)); // deterministic deck needed here; with random may sometimes deal an ACE to
    // dealer, which will cause insurance offer to be made
    assertEquals(game.isFinished(), false);
    assertEquals(game.isUserInputNeeded(), true);
    Round round = game.getCurrentRound();
    assertEquals(Round.RoundStatus.HAND_BEING_DEALT, round.getRoundStatus());

    playingStrategy.setAmountBet(MONEY_1);
    playGameWrapException(game);

    assertEquals(game.isFinished(), false);
    assertEquals(game.isUserInputNeeded(), true);
    round = game.getCurrentRound();
    assertEquals(Round.RoundStatus.HANDS_BEING_PLAYED_OUT, round.getRoundStatus());

    playingStrategy.setResponseToOffer(Offer.STAND);
    playGameWrapException(game);

    assertEquals(game.isFinished(), true);
    assertEquals(game.isUserInputNeeded(), false);
    assertNull(game.getCurrentRound());
    round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);
    assertEquals(game.getNumRoundsPlayed(), 1);
    assertEquals(game.getNumRoundsToPlay(), 1);
    assertEquals(game.getPastRounds().size(), 1);
  }
示例#27
0
  /**
   * Return the round that contains the given box score.
   *
   * @param oScore The score whose parent round is sought.
   * @return the Round that contains that score.
   */
  public Round getRoundOf(BoxScore oScore) {
    for (Round oRound : m_voRounds) if (oRound.contains(oScore)) return oRound;

    return null;
  }
示例#28
0
 private void eliminatePlayers(Round round) {
   for (TournamentPairing pair : round.getPairs()) {
     pair.eliminatePlayers();
   }
 }
  private void singleRound(
      BufferedWriter bw, String prefix, Round round, Map<Broker, double[]> resultMap)
      throws IOException {
    bw.write(prefix + "roundId;" + round.getRoundId() + separator);
    bw.write(prefix + "roundName;" + round.getRoundName() + separator);
    bw.write(prefix + "status;" + round.getState() + separator);

    bw.write(prefix + "StartTime;" + Utils.dateToStringFull(round.getStartTime()) + separator);
    bw.write(prefix + "Date from;" + Utils.dateToStringFull(round.getDateFrom()) + separator);
    bw.write(prefix + "Date to;" + Utils.dateToStringFull(round.getDateTo()) + separator);

    bw.write(prefix + "MaxBrokers;" + round.getMaxBrokers() + separator);
    bw.write(prefix + "Registered Brokers;" + round.getBrokerMap().size() + separator);
    //    bw.write(prefix + "MaxAgents;" + round.getMaxAgents() + separator);

    bw.write(prefix + "size1;" + round.getSize1() + separator);
    bw.write(prefix + "multiplier1;" + round.getMultiplier1() + separator);
    bw.write(prefix + "size2;" + round.getSize2() + separator);
    bw.write(prefix + "multiplier2;" + round.getMultiplier2() + separator);
    bw.write(prefix + "size3;" + round.getSize3() + separator);
    bw.write(prefix + "multiplier3;" + round.getMultiplier3() + separator);

    bw.write(prefix + "pomId;" + round.getPomId() + separator);
    bw.write(prefix + "Locations;" + round.getLocations() + separator);

    double[] avgsAndSDs = round.getAvgsAndSDsArray(resultMap);
    if (resultMap == null || resultMap.size() == 0 || avgsAndSDs == null) {
      return;
    }

    bw.write(separator);

    bw.write(prefix + "Average type 1;" + avgsAndSDs[0] + separator);
    bw.write(prefix + "Average type 2;" + avgsAndSDs[1] + separator);
    bw.write(prefix + "Average type 3;" + avgsAndSDs[2] + separator);

    bw.write(prefix + "Standard deviation type 1;" + avgsAndSDs[3] + separator);
    bw.write(prefix + "Standard deviation type 2;" + avgsAndSDs[4] + separator);
    bw.write(prefix + "Standard deviation type 3;" + avgsAndSDs[5] + separator);
    bw.write(separator);

    bw.write(
        prefix
            + "brokerId;brokerName;Size 1;Size 2;Size 3;"
            + "Total (not normalized);Size 1;Size 2;Size3;Total (normalized)"
            + separator);

    for (Map.Entry<Broker, double[]> entry : resultMap.entrySet()) {
      double[] results = entry.getValue();
      bw.write(
          String.format(
              "%s%s;%s;%f;%f;%f;%f;%f;%f;%f;%f%s",
              prefix,
              entry.getKey().getBrokerId(),
              entry.getKey().getBrokerName(),
              results[0],
              results[1],
              results[2],
              results[3],
              results[10],
              results[11],
              results[12],
              results[13],
              separator));
    }
  }
 private static String randomLocation(Round round) {
   double randLocation = Math.random() * round.getLocationsList().size();
   return round.getLocationsList().get((int) Math.floor(randLocation));
 }