Exemplo n.º 1
0
  @Override
  public PlayerModel deepCopy() {
    PlayerModel copiedPlayerModel =
        new PlayerModel(
            this.playerId,
            this.name,
            this.hero.deepCopy(),
            this.deck // TODO should be a deep copy, we're just using the index in boardmodel right
            // now to compensate..
            // oyachai: the use of the deck position index is actually an attempt to reduce memory
            // usage.
            );

    copiedPlayerModel.setMana(mana);
    copiedPlayerModel.setMaxMana(maxMana);
    copiedPlayerModel.setOverload(overload);
    copiedPlayerModel.deckPos = deckPos;
    copiedPlayerModel.fatigueDamage = fatigueDamage;
    copiedPlayerModel.numCardsUsed = numCardsUsed;

    for (Minion minion : minions) {
      copiedPlayerModel.minions.add((Minion) (minion).deepCopy());
    }

    for (final Card card : hand) {
      Card tc = card.deepCopy();
      copiedPlayerModel.placeCardHand(tc);
    }

    return copiedPlayerModel;
  }
Exemplo n.º 2
0
  public Object deepCopy() {
    BoardState newBoard = new BoardState();
    for (Iterator<Minion> iter = p0_minions_.iterator(); iter.hasNext(); ) {
      Minion tc = (Minion) (iter.next()).deepCopy();
      newBoard.p0_minions_.add(tc);
    }
    for (Iterator<Minion> iter = p1_minions_.iterator(); iter.hasNext(); ) {
      Minion tc = (Minion) (iter.next()).deepCopy();
      newBoard.p1_minions_.add(tc);
    }
    for (final Card card : p0_hand_) {
      Card tc = (Card) card.deepCopy();
      newBoard.placeCard_hand_p0(tc);
    }
    for (final Card card : p1_hand_) {
      Card tc = (Card) card.deepCopy();
      newBoard.placeCard_hand_p1(tc);
    }

    newBoard.setHero_p0((Hero) this.p0_hero_.deepCopy());
    newBoard.setHero_p1((Hero) this.p1_hero_.deepCopy());

    newBoard.p0_deckPos_ = this.p0_deckPos_;
    newBoard.p1_deckPos_ = this.p1_deckPos_;
    newBoard.p0_fatigueDamage_ = this.p0_fatigueDamage_;
    newBoard.p1_fatigueDamage_ = this.p1_fatigueDamage_;
    newBoard.p0_mana_ = this.p0_mana_;
    newBoard.p1_mana_ = this.p1_mana_;
    newBoard.p0_maxMana_ = this.p0_maxMana_;
    newBoard.p1_maxMana_ = this.p1_maxMana_;
    newBoard.p0_spellDamage_ = this.p0_spellDamage_;
    newBoard.p1_spellDamage_ = this.p1_spellDamage_;

    for (MinionPlayerIDPair minionIdPair : allMinionsFIFOList_) {
      if (minionIdPair.playerIndex_ == 0) {
        int minionIndex = p0_minions_.indexOf(minionIdPair.minion_);
        newBoard.allMinionsFIFOList_.add(
            new MinionPlayerIDPair(newBoard.p0_minions_.get(minionIndex), 0));
      } else if (minionIdPair.playerIndex_ == 1) {
        int minionIndex = p1_minions_.indexOf(minionIdPair.minion_);
        newBoard.allMinionsFIFOList_.add(
            new MinionPlayerIDPair(newBoard.p1_minions_.get(minionIndex), 1));
      }
    }
    return newBoard;
  }