Beispiel #1
0
  /** @return true if it played off other phases */
  private boolean playOffPhases() {
    Player current;
    ArrayList<Card> potentialCards = cardsThatCanBeLaidDown();
    ArrayList<Card> cardsToBeLaidDown = new ArrayList<Card>();

    for (int x = 0;
        x < getHand().getNumberOfCards();
        x++) { // get the cards that need to be added to the phases
      for (Card c : potentialCards) {
        if (c.getColor() == Color.BLACK) {
          if (c.getValue() == getHand().getCard(x).getValue())
            cardsToBeLaidDown.add(getHand().getCard(x));
        } else if (c.getColor() == getHand().getCard(x).getColor()) {
          cardsToBeLaidDown.add(getHand().getCard(x));
        }
      }
    }

    for (int player = 0; player < game.getNumberOfPlayers(); player++) { // add them to the phases
      current = game.getPlayer(player);
      if (current.hasLaidDownPhase()) {
        for (int group = 0; group < current.getNumberOfPhaseGroups(); group++) {
          for (Card c : cardsToBeLaidDown) {
            if (bestChoice(BEST_CHOICE_AT_FIFTY) && current.getPhaseGroup(group).addCard(c)) {
              playOffPhases();
              return true;
            }
          }
        }
      }
    }

    return false;
  }
Beispiel #2
0
  /** @return the card that is recommended to discard */
  private Card discardCard() {
    group = new Groups(this, getHand());
    int index = -1;
    Card[] discard = group.recommendDiscard();
    boolean search;

    do {
      search = true;
      index++;

      searching: // continue searching looks at the next card, until a good one is found
      while (search) {
        if (index >= discard.length) { // if it has looked through every card
          return discard[0];
        }
        if (discard[index].getValue() == Configuration.SKIP_VALUE) // automatically return a skip
        return discard[index];
        if (difficulty > 70) { // don't lay down cards the opponent has picked up
          for (Card p : pickedUpCards) {
            if (discard[index].getValue() == p.getValue()) {
              index++;
              continue searching;
            }
          }
        }
        if (difficulty > 30
            && nextPlayer
                .hasLaidDownPhase()) { // don't give an opponent something they can lay down
          for (Card l : cardsThatCanBeLaidDown()) {
            if (discard[index].getValue() == l.getValue()) {
              index++;
              continue searching;
            }
          }
        }
        if (difficulty > 30
            && group.getCompletePhaseGroups()
                != null) { // don't lay down a card part of a completed phaseGroup
          for (PhaseGroup g : group.getCompletePhaseGroups()) {
            for (int x = 0; x < g.getNumberOfCards(); x++) {
              if (g.getCard(x) == discard[index]) {
                index++;
                continue searching;
              }
            }
          }
        }
        search = false; // if the card has passed all these test, it can exit the search
      }
    } while (!bestChoice(BEST_CHOICE_AT_FIFTY));

    return discard[index];
  }
Beispiel #3
0
  /**
   * @return true if it is recommended to pick up a card, or false if it is recommended to draw a
   *     card
   */
  private boolean drawOrPickUp() {
    Card cardOnTopOfPile = game.getRound().getTopOfDiscardStack();

    if (hasLaidDownPhase()
        && difficulty > 30
        && bestChoice(
            BEST_CHOICE_AT_FIFTY)) { // pick up cards that can be played off laid down PhaseGroups
      for (Card c : cardsThatCanBeLaidDown()) {
        if (c.getColor() == cardOnTopOfPile.getColor()) {
          return true;
        } else if (c.getValue() == cardOnTopOfPile.getValue()) {
          return true;
        }
      }
    }

    if (difficulty > 30
        && addedPointValue(cardOnTopOfPile)
            < currentPointValue()) { // if the card improves the score of the player's hand
      if (difficulty < 70) // don't continue checking if an easy player
      return true;

      group = new Groups(this, getHand(), cardOnTopOfPile);
      if (group.cardInCompleteGroup(
          cardOnTopOfPile)) // if the card would be put in a complete group
      return true;
    }
    return false; // if any of the tests fail, draw from the deck
  }