示例#1
0
 /**
  * Reset all minions to clear their has_attacked state.
  *
  * <p>Call this function at the beginning of each turn
  */
 public void resetMinions() {
   p0_hero_.hasAttacked(false);
   p0_hero_.hasBeenUsed(false);
   p1_hero_.hasAttacked(false);
   p1_hero_.hasBeenUsed(false);
   for (Minion minion : p0_minions_) {
     minion.hasAttacked(false);
     minion.hasBeenUsed(false);
   }
   for (Minion minion : p1_minions_) {
     minion.hasAttacked(false);
     minion.hasBeenUsed(false);
   }
 }
示例#2
0
  @Test
  public void test0() throws HSException {

    // null case
    Minion target = board.data_.getCharacter(1, 0);
    Minion minion = board.data_.getMinion_p0(0);
    HearthTreeNode ret = minion.attack(1, target, board, deck, null);

    assertFalse(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(), 8);
    assertEquals(board.data_.getMana_p1(), 8);
    assertEquals(board.data_.getHero_p0().getHealth(), 30);
    assertEquals(board.data_.getHero_p1().getHealth(), 28);
    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);

    target = board.data_.getCharacter(1, 0);
    Hero hero = board.data_.getHero_p0();
    ret = hero.useHeroAbility(1, target, board, deck, null);
    assertEquals(board.data_.getNumCards_hand(), 1);
    assertEquals(board.data_.getNumMinions_p0(), 2);
    assertEquals(board.data_.getNumMinions_p1(), 2);
    assertEquals(board.data_.getMana_p0(), 6);
    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_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);

    minion.hasAttacked(false);
    target = board.data_.getCharacter(1, 2);
    ret = minion.attack(1, target, board, deck, null);
    assertEquals(board.data_.getNumCards_hand(), 1);
    assertEquals(board.data_.getNumMinions_p0(), 1);
    assertEquals(board.data_.getNumMinions_p1(), 2);
    assertEquals(board.data_.getMana_p0(), 6);
    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(), 7);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 5);

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

    minion.hasAttacked(false);
    target = board.data_.getCharacter(1, 2);
    ret = hero.useHeroAbility(1, target, board, deck, null);
    assertTrue(ret == null);
    assertEquals(board.data_.getNumCards_hand(), 1);
    assertEquals(board.data_.getNumMinions_p0(), 1);
    assertEquals(board.data_.getNumMinions_p1(), 2);
    assertEquals(board.data_.getMana_p0(), 6);
    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(), 7);
    assertEquals(board.data_.getMinion_p1(0).getHealth(), 2);
    assertEquals(board.data_.getMinion_p1(1).getHealth(), 5);

    assertEquals(board.data_.getMinion_p0(0).getTotalAttack(), 6);
    assertEquals(board.data_.getMinion_p1(0).getTotalAttack(), 2);
    assertEquals(board.data_.getMinion_p1(1).getTotalAttack(), 7);
  }
  @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());
  }
  // 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;
  }