Exemplo n.º 1
0
  public BoardState flipPlayers() {
    BoardState newState = (BoardState) this.deepCopy();
    MinionList p0_minions = newState.getMinions_p0();
    MinionList p1_minions = newState.getMinions_p1();
    int p0_mana = newState.getMana_p0();
    int p1_mana = newState.getMana_p1();
    int p0_maxMana = newState.getMaxMana_p0();
    int p1_maxMana = newState.getMaxMana_p1();

    newState.p0_hero_ = p1_hero_;
    newState.p1_hero_ = p0_hero_;
    newState.setMinions_p0(p1_minions);
    newState.setMinions_p1(p0_minions);
    newState.setMana_p0(p1_mana);
    newState.setMana_p1(p0_mana);
    newState.setMaxMana_p0(p1_maxMana);
    newState.setMaxMana_p1(p0_maxMana);
    newState.p0_hand_ = p1_hand_;
    newState.p1_hand_ = p0_hand_;
    newState.p0_deckPos_ = p1_deckPos_;
    newState.p1_deckPos_ = p0_deckPos_;
    newState.p0_fatigueDamage_ = p1_fatigueDamage_;
    newState.p1_fatigueDamage_ = p0_fatigueDamage_;
    newState.p0_spellDamage_ = p1_spellDamage_;
    newState.p1_spellDamage_ = p0_spellDamage_;

    for (MinionPlayerIDPair minionIdPair : newState.allMinionsFIFOList_) {
      minionIdPair.playerIndex_ = minionIdPair.playerIndex_ == 0 ? 1 : 0;
    }
    return newState;
  }
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;
  }
Exemplo n.º 3
0
  @Test
  public void testBoardState1() throws HSException {
    int numCards = 30;

    Card[] cards1 = new Card[numCards];
    Card[] cards2 = new Card[numCards];
    Card[] cards3 = new Card[numCards];

    for (int i = 0; i < numCards; ++i) {
      byte attack = (byte) ((int) (Math.random() * 6) + 1);
      byte health = (byte) ((int) (Math.random() * 2) + 1);
      byte mana = (byte) ((int) (0.5 * (attack + health)));

      attack = 1;
      health = 4;
      mana = 2;

      cards1[i] = new Minion("" + i, mana, attack, health, attack, health, health);
      cards3[i] = new Minion("" + i, mana, attack, health, attack, health, health);

      attack++;
      cards2[i] = new Minion("" + i, mana, attack, health, attack, health, health);
    }

    BoardState board1 = new BoardState();
    BoardState board2 = new BoardState();
    BoardState board3 = new BoardState();

    assertTrue(board1.equals(board2));

    board1.placeCard_hand_p0(cards1[0]);
    board3.placeCard_hand_p0(cards3[0]);

    assertFalse(board1.equals(board2));
    assertTrue(board1.equals(board3));

    board2.placeCard_hand_p0(cards3[0]);
    assertTrue(board1.equals(board2));

    board1.placeCard_hand_p0(cards1[1]);
    board3.placeCard_hand_p0(cards3[1]);
    board2.placeCard_hand_p0(cards2[1]);
    assertFalse(board1.equals(board2));
    assertTrue(board1.equals(board3));

    board1.placeMinion(0, (Minion) cards1[2]);
    board2.placeMinion(0, (Minion) cards2[2]);
    board2.placeMinion(0, (Minion) cards2[3]);
    board3.placeMinion(0, (Minion) cards3[2]);

    assertTrue(board1.equals(board3));
    assertFalse(board1.equals(board2));

    board1.placeMinion(1, (Minion) cards1[4]);
    board1.placeMinion(1, (Minion) cards1[5]);
    board3.placeMinion(1, (Minion) cards3[4]);
    board3.placeMinion(1, (Minion) cards3[5]);
    assertTrue(board1.equals(board3));

    log.info("board1 hashCode = " + board1.hashCode());
    log.info("board1 hashCode = " + board2.hashCode());
    log.info("board1 hashCode = " + board3.hashCode());
  }