Esempio n. 1
0
 /** @return the length of the run needed on this phase. Or 0 if there is no run needed. */
 int lengthOfRunNeeded() {
   for (int x = 0; x < Configuration.getNumberRequired(getPhase()); x++) {
     if (Configuration.getTypeRequired(getPhase(), x) == Configuration.RUN_PHASE)
       return Configuration.getLengthRequired(getPhase(), x);
   }
   return 0;
 }
Esempio n. 2
0
  /** If the nextPlayer picked up the last discard, add it to pickedUpCards */
  private void updateLastCardDiscarded() {
    int x = 0;
    while (this != game.getPlayer(x++)) {} // find the nextPlayer
    x = x % game.getNumberOfPlayers();
    nextPlayer = game.getPlayer(x);

    if (latestRound != game.getRoundNumber()) { // if it's a new Round, reset
      pickedUpCards = new ArrayList<Card>();
      lastCardDiscarded = null;
      latestRound = game.getRoundNumber();

      for (int y = 0; y < game.getNumberOfPlayers(); y++) { // ?????
        if (game.getPlayer(y) != this
            && (getScore() >= game.getPlayer(y).getScore()
                || getPhase() > game.getPlayer(y).getPhase())) { // ????
          setName(oldName);
          return;
        }
      }
      setName(oldName + "is#WINNING"); // ?????
    } else if (lastCardDiscarded != null
        && Configuration.getTypeRequired(nextPlayer.getPhase(), 0) == Configuration.SET_PHASE) {
      if (nextPlayer.drewFromDiscard())
        pickedUpCards.add(lastCardDiscarded); // add the card to picked up card if it was picked up
    }
  }
Esempio n. 3
0
  /**
   * @return an array with the sets that are needed on this phase. If there is only one set needed
   *     it will return an array length 1 with size of the set needed in [0] If there are two sets
   *     needed the array will be length two. The first element will be the bigger set needed. If
   *     there are no sets needed it will return null
   */
  int[] setsNeeded() {
    int numNeed = 0; // figure out the size of the array needed
    for (int x = 0; x < Configuration.getNumberRequired(getPhase()); x++) {
      if (Configuration.getTypeRequired(getPhase(), x) == Configuration.SET_PHASE) numNeed++;
    }
    if (numNeed > 0) {
      int[] need = new int[numNeed]; // fill the array with the size of the sets that are needed
      numNeed = 0;
      for (int x = 0; x < Configuration.getNumberRequired(getPhase()); x++) {
        if (Configuration.getTypeRequired(getPhase(), x) == Configuration.SET_PHASE)
          need[numNeed++] = Configuration.getLengthRequired(getPhase(), x);
      }

      return need;
    }
    return null;
  }
Esempio n. 4
0
  /**
   * This method is called by the game manager for the AIPlayer to complete a turn. This method
   * draws or picks up a card from the top of the discard pile, lays down the AIPlayers card, plays
   * off other peoples' laid down phases, and discards.
   */
  public void playTurn() {
    // all exceptions in this method are caught, because if this method throws an exception
    // the AIPlayer will not draw/discard a card and the program will freeze
    try {
      updateLastCardDiscarded();
    } catch (Exception e) {
      System.out.println("AIPlayer, lastCard: " + e.toString());
    }
    try {
      if (!(drawOrPickUp()
          ^ bestChoice(
              BEST_CHOICE_AT_FIFTY))) { // choose whether to draw from the deck or pick up from the
                                        // stack
        if (!game.getRound().drawFromDiscard()) // If picking up from the discard is not possible,
        game.getRound().drawFromDeck(); // draw from the deck instead
      } else {
        game.getRound().drawFromDeck();
      }
    } catch (Exception e) {
      System.out.println("AIPlayer, draw: " + e.toString());
      game.getRound().drawFromDeck(); // if something goes wrong, draw
    }

    try {
      group = new Groups(this, getHand());
      if (!hasLaidDownPhase()
          && group.getCompletePhaseGroups() != null
          && // if the AI player, hasn't laid down PhaseGroups
          group.getCompletePhaseGroups().length == Configuration.getNumberRequired(getPhase())
          && // will lay down the right number of phasesGroups
          getGame().getRound().getTurnNumber()
              >= 8 - (difficulty / 10)) // is past a certain turn number based off difficulty
      addPhaseGroups(group.getCompletePhaseGroups());
    } catch (Exception e) {
      System.out.println(
          "AIPlayer, laydown: " + e.toString()); // laid down all my cards Hand92,AI90afterAI74
    }

    try {
      if (hasLaidDownPhase()) playOffPhases();
    } catch (Exception e) {
      System.out.println("AIPlayer, playoff: " + e.toString());
    }

    try {
      lastCardDiscarded = discardCard();
      game.getRound().discard(lastCardDiscarded); // discard
    } catch (Phase10Exception e) {
    } catch (Exception e) {
      lastCardDiscarded = getHand().getCard(0);
      game.getRound().discard(lastCardDiscarded);
      System.out.println("AIPlayer, discard: " + e.toString());
    }
  }
Esempio n. 5
0
 /** @return true if it is the color phase, or false if it is not */
 boolean colorPhase() {
   if (Configuration.getTypeRequired(getPhase(), 0) == Configuration.COLOR_PHASE) return true;
   return false;
 }