Exemplo 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;
 }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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());
    }
  }