Exemplo n.º 1
0
  public double[][] learnKeepProbability(int iter) {
    double[][] probabilities = new double[2][52];
    Card[] keep = new Card[4];
    Card[] discard;
    for (int i = 0; i < iter; i++) {
      System.out.println("Iteration: " + i);
      Deck deck = new Deck(true);
      Hand hand = new Hand(deck, 6);
      discard = CribbageGame.selectDiscard(hand, 0, 0, true);
      hand.discardCard(discard[0]);
      hand.discardCard(discard[1]);
      for (int j = 0; j < keep.length; j++) keep[j] = hand.getCards().get(j);
      probabilities[0][keep[0].getCardIndex()]++;
      probabilities[0][keep[1].getCardIndex()]++;
      probabilities[0][keep[2].getCardIndex()]++;
      probabilities[0][keep[3].getCardIndex()]++;
      hand.addCard(discard[0]);
      hand.addCard(discard[1]);
      discard = CribbageGame.selectDiscard(hand, 0, 0, false);
      hand.discardCard(discard[0]);
      hand.discardCard(discard[1]);
      for (int j = 0; j < keep.length; j++) keep[j] = hand.getCards().get(j);
      probabilities[1][keep[0].getCardIndex()]++;
      probabilities[1][keep[1].getCardIndex()]++;
      probabilities[1][keep[2].getCardIndex()]++;
      probabilities[1][keep[3].getCardIndex()]++;
    }
    for (int i = 0; i < 52; i++) {
      probabilities[0][i] /= ((double) iter * 4.0);
      probabilities[1][i] /= ((double) iter * 4.0);
    }

    System.out.println("Probabilities for dealing:");
    for (int i = 0; i < 52; i++) {
      System.out.print(probabilities[0][i] + ", ");
    }

    System.out.println();
    System.out.println("Probabilities for not dealing:");
    for (int i = 0; i < 52; i++) {
      System.out.print(probabilities[1][i] + ", ");
    }

    return probabilities;
  }
Exemplo n.º 2
0
  public void testHandEvaluation() {
    Deck deck = new Deck(true);
    // Hand hand = new Hand(deck, 4);
    // Card card = deck.drawCard();

    ArrayList<Card> cards = new ArrayList<Card>();
    cards.add(new Card(Suit.clubs, 2));
    cards.add(new Card(Suit.clubs, 13));
    cards.add(new Card(Suit.diamonds, 3));
    cards.add(new Card(Suit.hearts, 4));
    Card card = new Card(Suit.clubs, 1);
    Hand hand = new Hand(cards);

    System.out.println(hand.getCards().toString() + " " + card.toString());

    System.out.println(ScoreEvaluator.evaluateHand(hand, card));
  }
Exemplo n.º 3
0
  public void testDiscard() {
    Deck deck = new Deck(true);
    // Hand hand = new Hand(deck, 6);
    Hand hand = new Hand();
    hand.addCard(new Card(Suit.diamonds, 3));
    hand.addCard(new Card(Suit.spades, 6));
    hand.addCard(new Card(Suit.clubs, 7));
    hand.addCard(new Card(Suit.spades, 7));
    hand.addCard(new Card(Suit.hearts, 11));
    hand.addCard(new Card(Suit.hearts, 12));

    System.out.println(hand.getCards().toString());

    Card[] discard = CribbageGame.selectDiscard(hand, 113, 103, false);
    System.out.println("Discard:");
    System.out.println(discard[0]);
    System.out.println(discard[1]);
  }