Esempio n. 1
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];
  }
Esempio n. 2
0
  /**
   * @return an ArrayList of all the type of the cards that can be laid down. If it's the number
   *     that's important the card will be black. If it's the color that's important the card will
   *     have a value of Configuration.WILD_VALUE
   */
  ArrayList<Card> cardsThatCanBeLaidDown() {
    ArrayList<Card> layDownAble = new ArrayList<Card>();
    layDownAble.add(new WildCard()); // a wild can always be laid down
    for (int x = 0; x < getGame().getNumberOfPlayers(); x++) {
      Player current = getGame().getPlayer(x);
      if (current.hasLaidDownPhase()) {
        for (int y = 0;
            y < current.getNumberOfPhaseGroups();
            y++) { // go through each person's phase groups who has laid down their phase
          PhaseGroup temp = current.getPhaseGroup(y);

          if (temp.getType()
              == Configuration
                  .RUN_PHASE) { // for a run, add one less than the first card's value and one more
                                // than the last
            if (temp.getCard(0).getValue()
                == Configuration.WILD_VALUE) // look at the hidden value if its wild
            layDownAble.add(new Card(((WildCard) temp.getCard(0)).getHiddenValue() - 1));
            else layDownAble.add(new Card(temp.getCard(0).getValue() - 1));
            if (temp.getCard(temp.getNumberOfCards() - 1).getValue() == Configuration.WILD_VALUE)
              layDownAble.add(
                  new Card(
                      ((WildCard) temp.getCard(temp.getNumberOfCards() - 1)).getHiddenValue() + 1));
            else
              layDownAble.add(new Card(temp.getCard(temp.getNumberOfCards() - 1).getValue() + 1));
          } else if (temp.getType()
              == Configuration.SET_PHASE) { // for set, add a card equal to the card value
            if (temp.getCard(0).getValue() != Configuration.WILD_VALUE)
              layDownAble.add(new Card(temp.getCard(0).getValue()));
            else layDownAble.add(new Card(((WildCard) temp.getCard(0)).getHiddenValue()));
          } else {
            layDownAble.add(new Card(temp.getCard(0).getColor(), Configuration.WILD_VALUE));
          }
        }
      }
    }

    return layDownAble;
  }