Esempio n. 1
0
  public double simulate(
      List<Optional<Card>> board,
      List<Optional<Card>> holeCards,
      List<Optional<Card>> opponentHoleCards) {
    int winOrTies = 0;
    // BestHandFinder aIfinder, opponentFinder;
    PokerHand aiHand, opponentHand;
    List<Optional<Card>> boardCopy;
    List<Optional<Card>> holeCardsCopy;
    List<Optional<Card>> opponentHoleCardsCopy;

    for (int i = 0; i < trials; i++) {
      cardProvider.removeCards(board);
      cardProvider.removeCards(holeCards);
      cardProvider.removeCards(opponentHoleCards);

      boardCopy = copy(board);
      holeCardsCopy = copy(holeCards);
      opponentHoleCardsCopy = copy(opponentHoleCards);
      assignCards(boardCopy, holeCardsCopy, opponentHoleCardsCopy);

      bestHandFinder.reset(fromOptionalToList(boardCopy), fromOptionalToList(holeCardsCopy));
      aiHand = bestHandFinder.find();
      bestHandFinder.reset(
          fromOptionalToList(boardCopy), fromOptionalToList(opponentHoleCardsCopy));
      opponentHand = bestHandFinder.find();
      if (aiHand.compareRanking(opponentHand) >= 0) {
        winOrTies++;
      }

      // refresh the card pool for second trial
      cardProvider.refreshCardPool();
    }
    return (winOrTies * 1.0 / trials);
  }
Esempio n. 2
0
 private void assignCardsHelper(List<Optional<Card>> cards) {
   Optional<Card> card;
   for (int i = 0; i < cards.size(); i++) {
     card = cards.get(i);
     if (!card.isPresent()) {
       cards.remove(i);
       cards.add(i, cardProvider.getRandomCard());
     }
   }
 }