public JSONObject toJSON() {
    JSONObject json = new JSONObject();

    json.put("name", name);
    json.put("playerId", playerId);
    json.put("hero", hero.toJSON());
    if (mana != maxMana) json.put("mana", mana);
    if (maxMana > 0) json.put("maxMana", maxMana);
    json.put("deckPos", deckPos);
    if (overload > 0) json.put("overload", overload);
    if (fatigueDamage > 0) json.put("fatigueDamage", fatigueDamage);

    if (minions.size() > 0) {
      JSONArray array = new JSONArray();
      for (Minion minion : minions) {
        array.put(minion.toJSON());
      }
      json.put("minions", array);
    }

    if (hand.size() > 0) {
      JSONArray array = new JSONArray();
      for (Card card : hand) {
        array.put(card.toJSON());
      }
      json.put("hand", array);
    }

    if (numCardsUsed > 0) {
      json.put("numCardsUsed", numCardsUsed);
    }

    return json;
  }
示例#2
0
  public JSONObject toJSON() {
    JSONObject json = new JSONObject();
    json.put("p0_mana", p0_mana_);
    json.put("p1_mana", p1_mana_);
    json.put("p0_maxMana", p0_maxMana_);
    json.put("p1_maxMana", p0_maxMana_);
    json.put("p0_deckPos", p0_deckPos_);
    json.put("p1_deckPos", p1_deckPos_);

    JSONArray p0_minions = new JSONArray();
    for (Minion minion : p0_minions_) p0_minions.put(minion.toJSON());
    json.put("p0_minions", p0_minions);

    JSONArray p1_minions = new JSONArray();
    for (Minion minion : p1_minions_) p1_minions.put(minion.toJSON());
    json.put("p1_minions", p1_minions);

    JSONArray p0_hand = new JSONArray();
    for (Card card : p0_hand_) p0_hand.put(card.toJSON());
    json.put("p0_hand", p0_hand);

    JSONArray p1_hand = new JSONArray();
    for (Card card : p1_hand_) p1_hand.put(card.toJSON());
    json.put("p1_hand", p1_hand);

    json.put("p0_hero", p0_hero_.toJSON());
    json.put("p1_hero", p1_hero_.toJSON());

    json.put("p0_fatigue", p0_fatigueDamage_);
    json.put("p1_fatigue", p1_fatigueDamage_);
    json.put("p0_spellDamage", p0_spellDamage_);
    json.put("p1_spellDamage", p1_spellDamage_);
    return json;
  }
示例#3
0
  @Test
  public void test1() throws HSException {

    Deck deck = null;

    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode res;
    Minion target = null;

    target = board.data_.getCharacter(1, 1);
    res = theCard.useOn(1, target, board, deck, null);
    assertFalse(res == null);
    assertTrue(res.data_.getNumCards_hand() == 0);
    assertTrue(res.data_.getNumMinions_p0() == 1);
    assertTrue(res.data_.getNumMinions_p1() == 3);
    assertTrue(res.data_.getMana_p0() == 10);
    assertTrue(res.data_.getMinion_p0(0).getHealth() == health0);
    assertTrue(res.data_.getMinion_p0(0).getTotalAttack() == attack0);
    assertTrue(res.data_.getMinion_p1(0).getHealth() == health0 - 2);
    assertTrue(res.data_.getMinion_p1(0).getTotalAttack() == attack0);
    assertTrue(res.data_.getMinion_p1(1).getHealth() == health1);
    assertTrue(res.data_.getMinion_p1(1).getTotalAttack() == attack0);
    assertTrue(res.data_.getMinion_p1(2).getHealth() == health0 - 2);
    assertTrue(res.data_.getMinion_p1(2).getTotalAttack() == attack0);
    assertTrue(res.data_.getHero_p0().getHealth() == 30);
    assertTrue(res.data_.getHero_p1().getHealth() == 30);
  }
  @Test
  public void test0() throws HSInvalidPlayerIndexException {

    // null case
    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode ret = theCard.useOn(0, 1, 0, board, deck, null);

    assertTrue(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 1);
    assertEquals(board.data_.getNumMinions_p0(), 2);
    assertEquals(board.data_.getNumMinions_p1(), 3);
    assertEquals(board.data_.getMana_p0(), 8);
    assertEquals(board.data_.getMana_p1(), 8);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 30);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 7);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(2).getHealth(), 7);

    assertEquals(board.data_.getMinion_p0(0).getAttack(), 2);
    assertEquals(board.data_.getMinion_p0(1).getAttack(), 7);
    assertEquals(board.data_.getMinion_p1(0).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(1).getAttack(), 2);
    assertEquals(board.data_.getMinion_p1(2).getAttack(), 7);

    assertTrue(board.data_.getMinion_p1(0).getDivineShield());
  }
  @Test
  public void test1() throws HSInvalidPlayerIndexException {

    Deck deck = null;

    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode res;

    res = theCard.useOn(0, 1, 1, board, deck, null);
    assertFalse(res == null);
    assertTrue(res.data_.getNumCards_hand() == 0);
    assertTrue(res.data_.getNumMinions_p0() == 1);
    assertTrue(res.data_.getNumMinions_p1() == 3);
    assertTrue(res.data_.getMana_p0() == 9);
    assertTrue(res.data_.getMinion_p0(0).getHealth() == health0);
    assertTrue(res.data_.getMinion_p0(0).getAttack() == attack0);
    assertTrue(res.data_.getMinion_p1(0).getHealth() == health0);
    assertTrue(res.data_.getMinion_p1(0).getAttack() == attack0 + 3);
    assertTrue(res.data_.getMinion_p1(1).getHealth() == health1);
    assertTrue(res.data_.getMinion_p1(1).getAttack() == attack0);
    assertTrue(res.data_.getMinion_p1(2).getHealth() == health0 - 2);
    assertTrue(res.data_.getMinion_p1(2).getAttack() == attack0);
    assertTrue(res.data_.getHero_p0().getHealth() == 30);
    assertTrue(res.data_.getHero_p1().getHealth() == 30);
  }
  @Test
  public void test1() throws HSException {

    Minion target = board.data_.getCharacter(1, 1);
    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode ret = theCard.useOn(1, target, board, deck, null);

    assertTrue(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 1);
    assertEquals(board.data_.getNumMinions_p0(), 2);
    assertEquals(board.data_.getNumMinions_p1(), 2);
    assertEquals(board.data_.getMana_p0(), 10);
    assertEquals(board.data_.getMana_p1(), 10);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 30);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 7);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 7);

    assertEquals(board.data_.getMinion_p0(0).getTotalAttack(), 2);
    assertEquals(board.data_.getMinion_p0(1).getTotalAttack(), 7);
    assertEquals(board.data_.getMinion_p1(0).getTotalAttack(), 2);
    assertEquals(board.data_.getMinion_p1(1).getTotalAttack(), 7);
  }
  @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;
  }
示例#8
0
  @Test
  public void test4() throws HSException {

    Minion target = board.data_.getCharacter(1, 2);
    for (int indx = 0; indx < 10; ++indx) board.data_.placeCard_hand_p1(new TheCoin());

    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode ret = theCard.useOn(1, target, board, deck, null);

    assertFalse(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumCards_hand_p1(), 10);
    assertEquals(board.data_.getNumMinions_p0(), 2);
    assertEquals(board.data_.getNumMinions_p1(), 1);
    assertEquals(board.data_.getMana_p0(), 8);
    assertEquals(board.data_.getMana_p1(), 10);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 30);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 2);

    assertEquals(board.data_.getMinion_p0(0).getTotalAttack(), 2);
    assertEquals(board.data_.getMinion_p0(1).getTotalAttack(), 4);
    assertEquals(board.data_.getMinion_p1(0).getTotalAttack(), 2);

    for (int indx = 0; indx < 10; ++indx)
      assertTrue(board.data_.getCard_hand_p1(0) instanceof TheCoin);
  }
 protected Card drawFromDeck(int index) {
   Card card = deck.drawCard(index);
   if (card == null) {
     return null;
   }
   card.setInHand(true);
   return card;
 }
示例#10
0
  @Test
  public void test3() throws HSInvalidPlayerIndexException {

    Deck deck = null;

    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode res;

    res = theCard.useOn(0, 1, 3, board, deck, null);
    assertTrue(res == null);
  }
示例#11
0
  @Test
  public void test3() throws HSException {

    Deck deck = null;

    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode res;
    Minion target = null;

    target = board.data_.getCharacter(1, 3);
    res = theCard.useOn(1, target, board, deck, null);
    assertTrue(res == null);
  }
示例#12
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;
  }
示例#13
0
 @Override
 public int hashCode() {
   int hs = p0_hand_.size();
   if (hs < 0) hs = 0;
   int res = hs + p0_minions_.size() * 10 + p1_minions_.size() * 100;
   res += (p0_mana_ <= 0 ? 0 : (p0_mana_ - 1) * 1000);
   res += ((p0_hero_.getHealth() + p1_hero_.getHealth()) % 100) * 10000;
   int th = 0;
   if (hs > 0) {
     Card cc = p0_hand_.get(0);
     try {
       Minion mm = (Minion) cc;
       th += (cc.hasBeenUsed() ? 1 : 0) + mm.getAttack() + mm.getHealth() + cc.getMana();
     } catch (ClassCastException e) {
       th += (cc.hasBeenUsed() ? 1 : 0) + cc.getMana();
     }
   }
   if (hs > 1) {
     Card cc = p0_hand_.get(1);
     try {
       Minion mm = (Minion) cc;
       th += (cc.hasBeenUsed() ? 1 : 0) + mm.getAttack() + mm.getHealth() + cc.getMana();
     } catch (ClassCastException e) {
       th += (cc.hasBeenUsed() ? 1 : 0) + cc.getMana();
     }
   }
   res += (th % 10) * 1000000;
   int mh0 = 0;
   if (p0_minions_.size() > 0) {
     mh0 += p0_minions_.get(0).getHealth();
   }
   if (p0_minions_.size() > 1) {
     mh0 += p0_minions_.get(1).getHealth();
   }
   res += (mh0 % 100) * 10000000;
   int mh1 = 0;
   if (p1_minions_.size() > 0) {
     mh1 += p1_minions_.get(0).getHealth();
   }
   if (p1_minions_.size() > 1) {
     mh1 += p1_minions_.get(1).getHealth();
   }
   res += (mh1 % 20) * 100000000;
   return res;
 }
示例#14
0
  @Test
  public void test2() throws HSException {

    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode res;

    try {
      Minion target = board.data_.getCharacter(0, 1);
      res = theCard.useOn(0, target, board, null, null);
      assertFalse(res == null);
      assertTrue(res.data_.getMana_p0() == 2);
      assertTrue(res.data_.getNumCards_hand() == 0);
      assertTrue(res.data_.getMinion_p0(0).getHealth() == health0);
      assertTrue(res.data_.getMinion_p0(0).getTotalAttack() == attack0);
      assertTrue(res.data_.getMinion_p0(0).getMaxHealth() == health0);
      assertTrue(res.data_.getMinion_p0(0).getTaunt());
    } catch (HSInvalidPlayerIndexException e) {
      e.printStackTrace();
      assertTrue(false);
    }
  }
示例#15
0
  @Test
  public void test2() throws HSException {

    board.data_.placeMinion(0, new IronfurGrizzly());
    Minion target = board.data_.getCharacter(1, 0);
    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode ret = theCard.useOn(1, target, board, deck, null);

    assertFalse(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 3);
    assertEquals(board.data_.getNumMinions_p1(), 2);
    assertEquals(board.data_.getMana_p0(), 4);
    assertEquals(board.data_.getMana_p1(), 4);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 25);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), health0);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), health1 - 1);
    assertEquals(board.data_.getMinion_p0(2).getHealth(), 3);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), health0);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), health1 - 1);
  }
  @Test
  public void test1() throws HSException {
    Card theCard = currentPlayer.getHand().get(0);
    HearthTreeNode ret = theCard.useOn(PlayerSide.CURRENT_PLAYER, CharacterIndex.MINION_1, board);
    assertNotNull(ret);
    currentPlayer = ret.data_.getCurrentPlayer();
    waitingPlayer = ret.data_.getWaitingPlayer();

    assertEquals(currentPlayer.getHand().size(), 0);
    assertEquals(currentPlayer.getNumMinions(), 3);
    assertEquals(waitingPlayer.getNumMinions(), 2);
    assertEquals(currentPlayer.getMana(), 6);
    assertEquals(waitingPlayer.getMana(), 10);
    assertEquals(currentPlayer.getHero().getHealth(), 30);
    assertEquals(waitingPlayer.getHero().getHealth(), 30);
    assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_1).getTotalHealth(), 4);
    assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_2).getTotalHealth(), 4);
    assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_3).getTotalHealth(), 7);
    assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_1).getTotalHealth(), 2);
    assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_2).getTotalHealth(), 2);

    assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_1).getTotalAttack(), 4);
    assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_2).getTotalAttack(), 4);
    assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_3).getTotalAttack(), 8);
    assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_1).getTotalAttack(), 2);
    assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_2).getTotalAttack(), 4);

    assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_1).getAuraAttack(), 1);
    assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_2).getAuraAttack(), 2);
    assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_3).getAuraAttack(), 1);
    assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_1).getAuraAttack(), 0);
    assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_2).getAuraAttack(), 1);

    assertTrue(currentPlayer.getCharacter(CharacterIndex.MINION_1).getTaunt());
    assertFalse(currentPlayer.getCharacter(CharacterIndex.MINION_2).getTaunt());
    assertTrue(currentPlayer.getCharacter(CharacterIndex.MINION_3).getTaunt());
  }
示例#17
0
  @Test
  public void test0() throws HSException {

    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode res;

    try {
      Minion target = board.data_.getCharacter(0, 0);
      res = theCard.useOn(0, target, board, null, null);
      assertTrue(res == null);
    } catch (HSInvalidPlayerIndexException e) {
      e.printStackTrace();
      assertTrue(false);
    }

    try {
      Minion target = board.data_.getCharacter(1, 0);
      res = theCard.useOn(1, target, board, null, null);
      assertTrue(res == null);
    } catch (HSInvalidPlayerIndexException e) {
      e.printStackTrace();
      assertTrue(false);
    }
  }
示例#18
0
 public void placeCardHand(Card card) {
   if (hand.isFull()) return;
   card.setInHand(true);
   hand.add(card);
 }
示例#19
0
  @Test
  public void test2() throws HSException {

    Minion target = board.data_.getCharacter(0, 0);
    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode ret = theCard.useOn(0, target, board, deck, null);

    assertFalse(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 2);
    assertEquals(board.data_.getNumMinions_p1(), 2);
    assertEquals(board.data_.getMana_p0(), 7);
    assertEquals(board.data_.getMana_p1(), 10);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 30);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 7);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 7);

    assertEquals(board.data_.getMinion_p0(0).getTotalAttack(), 4);
    assertEquals(board.data_.getMinion_p0(1).getTotalAttack(), 9);
    assertEquals(board.data_.getMinion_p1(0).getTotalAttack(), 2);
    assertEquals(board.data_.getMinion_p1(1).getTotalAttack(), 7);

    assertEquals(board.data_.getHero_p0().getExtraAttackUntilTurnEnd(), 2);
    assertEquals(board.data_.getHero_p1().getExtraAttackUntilTurnEnd(), 0);
    assertEquals(board.data_.getMinion_p0(0).getExtraAttackUntilTurnEnd(), 2);
    assertEquals(board.data_.getMinion_p0(1).getExtraAttackUntilTurnEnd(), 2);
    assertEquals(board.data_.getMinion_p1(0).getExtraAttackUntilTurnEnd(), 0);
    assertEquals(board.data_.getMinion_p1(1).getExtraAttackUntilTurnEnd(), 0);

    target = board.data_.getCharacter(1, 2);
    ret = board.data_.getMinion_p0(0).attack(1, target, board, deck, null);

    assertFalse(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 1);
    assertEquals(board.data_.getNumMinions_p1(), 2);
    assertEquals(board.data_.getMana_p0(), 7);
    assertEquals(board.data_.getMana_p1(), 10);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 30);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 7);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 3);

    assertEquals(board.data_.getMinion_p0(0).getTotalAttack(), 8);
    assertEquals(board.data_.getMinion_p1(0).getTotalAttack(), 2);
    assertEquals(board.data_.getMinion_p1(1).getTotalAttack(), 7);

    assertEquals(board.data_.getHero_p0().getExtraAttackUntilTurnEnd(), 2);
    assertEquals(board.data_.getHero_p1().getExtraAttackUntilTurnEnd(), 0);
    assertEquals(board.data_.getMinion_p0(0).getExtraAttackUntilTurnEnd(), 2);
    assertEquals(board.data_.getMinion_p1(0).getExtraAttackUntilTurnEnd(), 0);
    assertEquals(board.data_.getMinion_p1(1).getExtraAttackUntilTurnEnd(), 0);

    target = board.data_.getCharacter(1, 2);
    ret = board.data_.getHero_p0().attack(1, target, board, deck, null);

    assertFalse(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 1);
    assertEquals(board.data_.getNumMinions_p1(), 2);
    assertEquals(board.data_.getMana_p0(), 7);
    assertEquals(board.data_.getMana_p1(), 10);
    assertEquals(board.data_.getHero_p0().getHealth(), 23);
    assertEquals(board.data_.getHero_p1().getHealth(), 30);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 7);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 1);

    assertEquals(board.data_.getMinion_p0(0).getTotalAttack(), 8);
    assertEquals(board.data_.getMinion_p1(0).getTotalAttack(), 2);
    assertEquals(board.data_.getMinion_p1(1).getTotalAttack(), 7);

    assertEquals(board.data_.getHero_p0().getExtraAttackUntilTurnEnd(), 2);
    assertEquals(board.data_.getHero_p1().getExtraAttackUntilTurnEnd(), 0);
    assertEquals(board.data_.getMinion_p0(0).getExtraAttackUntilTurnEnd(), 2);
    assertEquals(board.data_.getMinion_p1(0).getExtraAttackUntilTurnEnd(), 0);
    assertEquals(board.data_.getMinion_p1(1).getExtraAttackUntilTurnEnd(), 0);
  }
示例#20
0
  @Test
  public void test2() throws HSInvalidPlayerIndexException {

    // null case
    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode ret = theCard.useOn(0, 0, 3, board, deck, null);

    assertFalse(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 3);
    assertEquals(board.data_.getNumMinions_p1(), 3);
    assertEquals(board.data_.getMana_p0(), 5);
    assertEquals(board.data_.getMana_p1(), 8);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 30);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 7);
    assertEquals(board.data_.getMinion_p0(2).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(2).getHealth(), 7);

    assertEquals(board.data_.getMinion_p0(0).getAttack(), 2);
    assertEquals(board.data_.getMinion_p0(1).getAttack(), 7);
    assertEquals(board.data_.getMinion_p0(2).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(0).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(1).getAttack(), 2);
    assertEquals(board.data_.getMinion_p1(2).getAttack(), 7);

    assertTrue(board.data_.getMinion_p1(0).getDivineShield());
    assertTrue(board.data_.getMinion_p0(2).getDivineShield());

    // ------------------------------------------------------------
    // Attacking with divine shield vs Hero, divine shield should
    // stay on
    // ------------------------------------------------------------
    Minion m0 = board.data_.getMinion_p0(2);
    m0.hasAttacked(false);
    ret = m0.attack(3, 1, 0, board, deck, null);

    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 3);
    assertEquals(board.data_.getNumMinions_p1(), 3);
    assertEquals(board.data_.getMana_p0(), 5);
    assertEquals(board.data_.getMana_p1(), 8);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 26);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 7);
    assertEquals(board.data_.getMinion_p0(2).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(2).getHealth(), 7);

    assertEquals(board.data_.getMinion_p0(0).getAttack(), 2);
    assertEquals(board.data_.getMinion_p0(1).getAttack(), 7);
    assertEquals(board.data_.getMinion_p0(2).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(0).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(1).getAttack(), 2);
    assertEquals(board.data_.getMinion_p1(2).getAttack(), 7);

    assertTrue(board.data_.getMinion_p1(0).getDivineShield());
    assertTrue(board.data_.getMinion_p0(2).getDivineShield());

    // ------------------------------------------------------------
    // Attacking with divine shield
    // ------------------------------------------------------------
    Minion m1 = board.data_.getMinion_p0(2);
    m1.hasAttacked(false);
    ret = m1.attack(3, 1, 3, board, deck, null);

    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 3);
    assertEquals(board.data_.getNumMinions_p1(), 3);
    assertEquals(board.data_.getMana_p0(), 5);
    assertEquals(board.data_.getMana_p1(), 8);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 26);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 7);
    assertEquals(board.data_.getMinion_p0(2).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(2).getHealth(), 3);

    assertEquals(board.data_.getMinion_p0(0).getAttack(), 2);
    assertEquals(board.data_.getMinion_p0(1).getAttack(), 7);
    assertEquals(board.data_.getMinion_p0(2).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(0).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(1).getAttack(), 2);
    assertEquals(board.data_.getMinion_p1(2).getAttack(), 7);

    assertTrue(board.data_.getMinion_p1(0).getDivineShield());
    assertFalse(board.data_.getMinion_p0(2).getDivineShield());

    // ------------------------------------------------------------
    // Being attacked with a divine shield
    // ------------------------------------------------------------
    Minion m2 = board.data_.getMinion_p0(1);
    m2.hasAttacked(false);
    ret = m2.attack(2, 1, 1, board, deck, null);

    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 3);
    assertEquals(board.data_.getNumMinions_p1(), 3);
    assertEquals(board.data_.getMana_p0(), 5);
    assertEquals(board.data_.getMana_p1(), 8);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 26);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 3);
    assertEquals(board.data_.getMinion_p0(2).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(2).getHealth(), 3);

    assertEquals(board.data_.getMinion_p0(0).getAttack(), 2);
    assertEquals(board.data_.getMinion_p0(1).getAttack(), 7);
    assertEquals(board.data_.getMinion_p0(2).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(0).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(1).getAttack(), 2);
    assertEquals(board.data_.getMinion_p1(2).getAttack(), 7);

    assertFalse(board.data_.getMinion_p1(0).getDivineShield());
    assertFalse(board.data_.getMinion_p0(2).getDivineShield());

    // ------------------------------------------------------------
    // Being attacked with a divine shield that wore off
    // ------------------------------------------------------------
    Minion m3 = board.data_.getMinion_p0(2);
    m3.hasAttacked(false);
    ret = m3.attack(3, 1, 3, board, deck, null);

    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 2);
    assertEquals(board.data_.getNumMinions_p1(), 2);
    assertEquals(board.data_.getMana_p0(), 5);
    assertEquals(board.data_.getMana_p1(), 8);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 26);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 3);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 1);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 2);

    assertEquals(board.data_.getMinion_p0(0).getAttack(), 2);
    assertEquals(board.data_.getMinion_p0(1).getAttack(), 7);
    assertEquals(board.data_.getMinion_p1(0).getAttack(), 4);
    assertEquals(board.data_.getMinion_p1(1).getAttack(), 2);

    assertFalse(board.data_.getMinion_p1(0).getDivineShield());
  }
示例#21
0
  @Test
  public void test2() throws HSException {

    Minion target = board.data_.getCharacter(0, 1);
    Card theCard = board.data_.getCard_hand_p0(0);
    HearthTreeNode ret = theCard.useOn(0, target, board, deck, null);

    assertFalse(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 0);
    assertEquals(board.data_.getNumMinions_p0(), 3);
    assertEquals(board.data_.getNumMinions_p1(), 3);
    assertEquals(board.data_.getMana_p0(), 6);
    assertEquals(board.data_.getMana_p1(), 4);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 30);
    assertEquals(board.data_.getMinion_p0(0).getHealth(), health0);
    assertEquals(board.data_.getMinion_p0(1).getHealth(), 1);
    assertEquals(board.data_.getMinion_p0(2).getHealth(), health1 - 1);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), health0);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), health1 - 1);

    assertEquals(board.data_.getMinion_p0(0).getTotalAttack(), attack0);
    assertEquals(board.data_.getMinion_p0(1).getTotalAttack(), 1);
    assertEquals(board.data_.getMinion_p0(2).getTotalAttack(), attack0);

    assertEquals(board.numChildren(), 7);

    {
      HearthTreeNode child = board.getChildren().get(0);
      assertEquals(child.data_.getNumCards_hand(), 0);
      assertEquals(child.data_.getNumMinions_p0(), 3);
      assertEquals(child.data_.getNumMinions_p1(), 3);
      assertEquals(child.data_.getMana_p0(), 6);
      assertEquals(child.data_.getMana_p1(), 4);
      assertEquals(child.data_.getHero_p0().getHealth(), 29);
      assertEquals(child.data_.getHero_p1().getHealth(), 30);
      assertEquals(child.data_.getMinion_p0(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p0(1).getHealth(), 1);
      assertEquals(child.data_.getMinion_p0(2).getHealth(), health1 - 1);
      assertEquals(child.data_.getMinion_p1(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p1(1).getHealth(), health1 - 1);

      assertEquals(child.data_.getMinion_p0(0).getTotalAttack(), attack0);
      assertEquals(child.data_.getMinion_p0(1).getTotalAttack(), 1);
      assertEquals(child.data_.getMinion_p0(2).getTotalAttack(), attack0);
    }

    {
      HearthTreeNode child = board.getChildren().get(1);
      assertEquals(child.data_.getNumCards_hand(), 0);
      assertEquals(child.data_.getNumMinions_p0(), 3);
      assertEquals(child.data_.getNumMinions_p1(), 3);
      assertEquals(child.data_.getMana_p0(), 6);
      assertEquals(child.data_.getMana_p1(), 4);
      assertEquals(child.data_.getHero_p0().getHealth(), 30);
      assertEquals(child.data_.getHero_p1().getHealth(), 30);
      assertEquals(child.data_.getMinion_p0(0).getHealth(), health0 - 1);
      assertEquals(child.data_.getMinion_p0(1).getHealth(), 1);
      assertEquals(child.data_.getMinion_p0(2).getHealth(), health1 - 1);
      assertEquals(child.data_.getMinion_p1(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p1(1).getHealth(), health1 - 1);

      assertEquals(child.data_.getMinion_p0(0).getTotalAttack(), attack0);
      assertEquals(child.data_.getMinion_p0(1).getTotalAttack(), 1);
      assertEquals(child.data_.getMinion_p0(2).getTotalAttack(), attack0);
    }

    {
      HearthTreeNode child = board.getChildren().get(2);
      assertEquals(child.data_.getNumCards_hand(), 0);
      assertEquals(child.data_.getNumMinions_p0(), 3);
      assertEquals(child.data_.getNumMinions_p1(), 3);
      assertEquals(child.data_.getMana_p0(), 6);
      assertEquals(child.data_.getMana_p1(), 4);
      assertEquals(child.data_.getHero_p0().getHealth(), 30);
      assertEquals(child.data_.getHero_p1().getHealth(), 30);
      assertEquals(child.data_.getMinion_p0(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p0(1).getHealth(), 1);
      assertEquals(child.data_.getMinion_p0(2).getHealth(), health1 - 1 - 1);
      assertEquals(child.data_.getMinion_p1(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p1(1).getHealth(), health1 - 1);

      assertEquals(child.data_.getMinion_p0(0).getTotalAttack(), attack0);
      assertEquals(child.data_.getMinion_p0(1).getTotalAttack(), 1);
      assertEquals(child.data_.getMinion_p0(2).getTotalAttack(), attack0);
    }

    {
      HearthTreeNode child = board.getChildren().get(3);
      assertEquals(child.data_.getNumCards_hand(), 0);
      assertEquals(child.data_.getNumMinions_p0(), 3);
      assertEquals(child.data_.getNumMinions_p1(), 3);
      assertEquals(child.data_.getMana_p0(), 6);
      assertEquals(child.data_.getMana_p1(), 4);
      assertEquals(child.data_.getHero_p0().getHealth(), 30);
      assertEquals(child.data_.getHero_p1().getHealth(), 29);
      assertEquals(child.data_.getMinion_p0(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p0(1).getHealth(), 1);
      assertEquals(child.data_.getMinion_p0(2).getHealth(), health1 - 1);
      assertEquals(child.data_.getMinion_p1(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p1(1).getHealth(), health1 - 1);

      assertEquals(child.data_.getMinion_p0(0).getTotalAttack(), attack0);
      assertEquals(child.data_.getMinion_p0(1).getTotalAttack(), 1);
      assertEquals(child.data_.getMinion_p0(2).getTotalAttack(), attack0);
    }

    {
      HearthTreeNode child = board.getChildren().get(4);
      assertEquals(child.data_.getNumCards_hand(), 0);
      assertEquals(child.data_.getNumMinions_p0(), 3);
      assertEquals(child.data_.getNumMinions_p1(), 3);
      assertEquals(child.data_.getMana_p0(), 6);
      assertEquals(child.data_.getMana_p1(), 4);
      assertEquals(child.data_.getHero_p0().getHealth(), 30);
      assertEquals(child.data_.getHero_p1().getHealth(), 30);
      assertEquals(child.data_.getMinion_p0(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p0(1).getHealth(), 1);
      assertEquals(child.data_.getMinion_p0(2).getHealth(), health1 - 1);
      assertEquals(child.data_.getMinion_p1(0).getHealth(), health0 - 1);
      assertEquals(child.data_.getMinion_p1(1).getHealth(), health1 - 1);

      assertEquals(child.data_.getMinion_p0(0).getTotalAttack(), attack0);
      assertEquals(child.data_.getMinion_p0(1).getTotalAttack(), 1);
      assertEquals(child.data_.getMinion_p0(2).getTotalAttack(), attack0);
    }

    {
      HearthTreeNode child = board.getChildren().get(5);
      assertEquals(child.data_.getNumCards_hand(), 0);
      assertEquals(child.data_.getNumMinions_p0(), 3);
      assertEquals(child.data_.getNumMinions_p1(), 3);
      assertEquals(child.data_.getMana_p0(), 6);
      assertEquals(child.data_.getMana_p1(), 4);
      assertEquals(child.data_.getHero_p0().getHealth(), 30);
      assertEquals(child.data_.getHero_p1().getHealth(), 30);
      assertEquals(child.data_.getMinion_p0(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p0(1).getHealth(), 1);
      assertEquals(child.data_.getMinion_p0(2).getHealth(), health1 - 1);
      assertEquals(child.data_.getMinion_p1(0).getHealth(), health0);
      assertEquals(child.data_.getMinion_p1(1).getHealth(), health1 - 1 - 1);

      assertEquals(child.data_.getMinion_p0(0).getTotalAttack(), attack0);
      assertEquals(child.data_.getMinion_p0(1).getTotalAttack(), 1);
      assertEquals(child.data_.getMinion_p0(2).getTotalAttack(), attack0);
    }

    {
      HearthTreeNode child = board.getChildren().get(6);
      assertEquals(child.data_.getNumCards_hand(), 0);
      assertEquals(child.data_.getNumMinions_p0(), 2);
      assertEquals(child.data_.getNumMinions_p1(), 2);
      assertEquals(child.data_.getMana_p0(), 6);
      assertEquals(child.data_.getMana_p1(), 4);
      assertEquals(child.data_.getHero_p0().getHealth(), 28);
      assertEquals(child.data_.getHero_p1().getHealth(), 28);
      assertEquals(child.data_.getMinion_p0(0).getTotalHealth(), health0 - 2);
      assertEquals(child.data_.getMinion_p0(1).getTotalHealth(), health1 - 1 - 2);
      assertEquals(child.data_.getMinion_p1(0).getTotalHealth(), health0 - 2);
      assertEquals(child.data_.getMinion_p1(1).getTotalHealth(), health1 - 1 - 2);

      assertEquals(child.data_.getMinion_p0(0).getTotalAttack(), attack0);
      assertEquals(child.data_.getMinion_p0(1).getTotalAttack(), attack0);
    }
  }
示例#22
0
 public void placeCard_hand(int playerIndex, Card card) throws HSInvalidPlayerIndexException {
   card.isInHand(true);
   if (playerIndex == 0) p0_hand_.add(card);
   else if (playerIndex == 1) p1_hand_.add(card);
   else throw new HSInvalidPlayerIndexException();
 }
示例#23
0
 public void placeCard_hand_p1(Card card) {
   card.isInHand(true);
   p1_hand_.add(card);
 }
示例#24
0
 /** Reset the has_been_used state of the cards in hand */
 public void resetHand() {
   for (Card card : p0_hand_) {
     card.hasBeenUsed(false);
   }
 }
示例#25
0
  // TODO Unused?
  public HearthTreeNode perform(HearthTreeNode boardState) throws HSException {
    HearthTreeNode toRet = boardState;
    PlayerModel actingPlayer =
        actionPerformerPlayerSide != null
            ? boardState.data_.modelForSide(actionPerformerPlayerSide)
            : null;
    PlayerModel targetPlayer =
        targetPlayerSide != null ? boardState.data_.modelForSide(targetPlayerSide) : null;

    switch (verb_) {
      case USE_CARD:
        {
          Card card = actingPlayer.getHand().get(cardOrCharacterIndex_);
          toRet = card.useOn(targetPlayerSide, targetCharacterIndex, toRet);
        }
        break;
      case HERO_ABILITY:
        {
          Hero hero = actingPlayer.getHero();
          Minion target = targetPlayer.getCharacter(targetCharacterIndex);
          toRet = hero.useHeroAbility(targetPlayerSide, target, toRet);
        }
        break;
      case ATTACK:
        {
          Minion attacker =
              actingPlayer.getCharacter(CharacterIndex.fromInteger(cardOrCharacterIndex_));
          toRet = attacker.attack(targetPlayerSide, targetCharacterIndex, toRet);
        }
        break;
      case UNTARGETABLE_BATTLECRY:
        {
          Minion minion =
              actingPlayer.getCharacter(CharacterIndex.fromInteger(cardOrCharacterIndex_));
          toRet = minion.useUntargetableBattlecry(targetCharacterIndex, toRet);
          break;
        }
      case TARGETABLE_BATTLECRY:
        {
          Minion minion =
              actingPlayer.getCharacter(CharacterIndex.fromInteger(cardOrCharacterIndex_));
          toRet = minion.useTargetableBattlecry(targetPlayerSide, targetCharacterIndex, toRet);
          break;
        }
      case START_TURN:
        {
          toRet = new HearthTreeNode(Game.beginTurn(boardState.data_.deepCopy()));
          break;
        }
      case END_TURN:
        {
          toRet = new HearthTreeNode(Game.endTurn(boardState.data_.deepCopy()).flipPlayers());
          break;
        }
      case DO_NOT_USE_CARD:
        {
          for (Card c : actingPlayer.getHand()) {
            c.hasBeenUsed(true);
          }
          break;
        }
      case DO_NOT_ATTACK:
        {
          for (Minion minion : actingPlayer.getMinions()) {
            minion.hasAttacked(true);
          }
          actingPlayer.getHero().hasAttacked(true);
          break;
        }
      case DO_NOT_USE_HEROPOWER:
        {
          actingPlayer.getHero().hasBeenUsed(true);
          break;
        }
      case RNG:
        {
          // We need to perform the current state again if the children don't exist yet. This can
          // happen in certain replay scenarios.
          // Do not do this if the previous action was *also* RNG or we will end up in an infinite
          // loop.
          if (toRet.isLeaf() && boardState.getAction().verb_ != Verb.RNG) {
            boardState.data_.getCurrentPlayer().addNumCardsUsed((byte) -1); // do not double count
            toRet = boardState.getAction().perform(boardState);
          }
          // RNG has declared this child happened
          toRet = toRet.getChildren().get(cardOrCharacterIndex_);
          break;
        }
      case DRAW_CARDS:
        {
          // Note, this action only supports drawing cards from the deck. Cards like Ysera or
          // Webspinner need to be implemented using RNG children.
          for (int indx = 0; indx < cardOrCharacterIndex_; ++indx) {
            actingPlayer.drawNextCardFromDeck();
          }
          break;
        }
    }
    return toRet;
  }