Ejemplo n.º 1
0
  EquityCalculator(Card[] hand, Card[] board, int skip) {
    cardByID = new Card[cardCount];
    usedCards = new boolean[cardCount];
    winningBoards = 0;
    possibleBoards = 0;
    this.skip = skip;
    skip2 = 2;

    for (int i = 0; i < cardCount; i++) cardByID[i] = CardUtils.getCardByID(i);

    setHand(hand);
    if (board != null) setBoard(board);
  }
Ejemplo n.º 2
0
  public void processInput(String input) {
    String[] tokens = input.split(" ");
    String word = tokens[0];
    if ("NEWGAME".compareToIgnoreCase(word) == 0) {
      String myName = tokens[1];
      String oppName = tokens[2];
      int stackSize = Integer.parseInt(tokens[3]);
      int bb = Integer.parseInt(tokens[4]);
      numHands = Integer.parseInt(tokens[5]);

      maj = new Historian(myName, oppName, stackSize, bb);
      // newGame();
    } else if ("KEYVALUE".compareToIgnoreCase(word) == 0) {
      if (tokens.length < 2) return;
      String[] smallTokens = tokens[1].split(":");
      if (smallTokens.length < 2) return;
      maj.notifyValue(smallTokens[0], smallTokens[1], tokens[2]); // the key value pair
    } else if ("NEWHAND".compareToIgnoreCase(word) == 0) {
      int handNum = Integer.parseInt(tokens[1]);

      if (handNum == numHands / 4) cons = true;
      if (handNum == numHands * 2 / 4) {
        System.out.println("Reg earnings: " + regEarnings + " consEarnings: " + consEarnings);
        if (consEarnings > regEarnings) cons = true;
        else cons = false;
      }

      System.out.println("Using conservative brain? " + cons);

      Card[] hand = new Card[3];
      hand[0] = CardUtils.getCardByString(tokens[3]);
      hand[1] = CardUtils.getCardByString(tokens[4]);
      hand[2] = CardUtils.getCardByString(tokens[5]);

      double timebank = Double.parseDouble(tokens[8]);

      Random rand = new Random();

      boolean callRaise = false, checkRaise = false;

      if (rand.nextDouble() < 0.5) {
        callRaise = true;
      }
      if (rand.nextDouble() < 0.5) {
        checkRaise = true;
      }

      if (cons) brain = new ConservativeBrain(maj, hand, timebank, callRaise, checkRaise);
      else brain = new Brain(maj, hand, timebank, callRaise, checkRaise);

      brain.handId = Integer.parseInt(tokens[1]);
      brain.button = Boolean.parseBoolean(tokens[2]);

      brain.board = new Card[5];

      brain.myBank = Integer.parseInt(tokens[6]);
      brain.oppBank = Integer.parseInt(tokens[7]);

      // newHand();
    } else if ("GETACTION".compareToIgnoreCase(word) == 0) {
      brain.potSize = Integer.parseInt(tokens[1]);

      brain.numBoardCards = Integer.parseInt(tokens[2]);
      int i = 3;
      for (; i < brain.numBoardCards + 3; i++)
        brain.board[i - 3] = CardUtils.getCardByString(tokens[i]);

      brain.numLastActions = Integer.parseInt(tokens[i]);
      brain.lastActions = new PerformedAction[brain.numLastActions];
      int j = i + 1;
      for (; j < brain.numLastActions + i + 1; j++) {
        brain.lastActions[j - i - 1] = ActionUtils.getPerformedActionByString(tokens[j]);
      }

      brain.numLegalActions = Integer.parseInt(tokens[j]);
      brain.legalActions = new LegalAction[brain.numLegalActions];

      int k = j + 1;
      for (; k < brain.numLegalActions + j + 1; k++)
        brain.legalActions[k - j - 1] = ActionUtils.getLegalActionByString(tokens[k]);

      brain.timebank = Double.parseDouble(tokens[k]);

      // String res = ActionUtils.performedActionToString((PerformedAction)brain.act());
      // System.out.println(res);
      outStream.println(ActionUtils.performedActionToString((PerformedAction) brain.act()));
    } else if ("HANDOVER".compareToIgnoreCase(word) == 0) {
      brain.myBank = Integer.parseInt(tokens[1]);
      brain.oppBank = Integer.parseInt(tokens[2]);

      if (cons) {
        consEarnings = brain.myBank - regEarnings;
      } else {
        regEarnings = brain.myBank;
      }

      brain.numBoardCards = Integer.parseInt(tokens[3]);
      int i = 4;
      for (; i < brain.numBoardCards + 4; i++)
        brain.board[i - 4] = CardUtils.getCardByString(tokens[i]);

      brain.numLastActions = Integer.parseInt(tokens[i]);
      brain.lastActions = new PerformedAction[brain.numLastActions];
      int j = i + 1;
      for (; j < brain.numLastActions + i + 1; j++) {
        brain.lastActions[j - i - 1] = ActionUtils.getPerformedActionByString(tokens[j]);
      }

      maj.update(brain.lastActions);
      maj.numHandsPlayed++;

      System.out.println("\nPFR: " + maj.getPFR());
      System.out.println("SDW: " + maj.getSDWRate() + "\n");
    } else if ("REQUESTKEYVALUES".compareToIgnoreCase(word) == 0) {
      // At the end, engine will allow bot to send key/value pairs to store.
      // FINISH indicates no more to store.
      outStream.println("DELETE " + maj.oppName);
      outStream.println("PUT " + maj.oppName + ":PFR " + maj.getValueToSave("PFR"));
      outStream.println("PUT " + maj.oppName + ":SDW " + maj.getValueToSave("SDW"));
      outStream.println("FINISH");
    }
  }