Skip to content

Commit

Permalink
more crashing bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oyachai committed Jun 23, 2015
1 parent 79b1764 commit 92be4d9
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 41 deletions.
6 changes: 1 addition & 5 deletions src/main/java/com/hearthsim/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,7 @@ protected HearthTreeNode createRngNodeWithChildren(HearthTreeNode boardState, Co

protected HearthTreeNode createNodeWithChildren(HearthTreeNode boardState, Collection<HearthTreeNode> children) {
if (children != null) {
if (children.size() == 1) {
boardState = children.stream().findAny().get();
} else if (children.size() > 1) {
boardState.addChildren(children);
}
boardState.addChildren(children);
}
return boardState;
}
Expand Down
29 changes: 21 additions & 8 deletions src/main/java/com/hearthsim/card/minion/Minion.java
Original file line number Diff line number Diff line change
Expand Up @@ -624,18 +624,31 @@ public HearthTreeNode summonMinion(PlayerSide targetSide, CharacterIndex targetM
Minion origin;
CharacterIndex originCharacterIndex = toRet.data_.modelForSide(PlayerSide.CURRENT_PLAYER).getIndexForCharacter(this);

ArrayList<HearthTreeNode> children = new ArrayList<>();
for (CharacterIndex.CharacterLocation characterLocation : toRet.data_) {
// Find out if there are going to be more than one target match
int numTargets = 0;
CharacterIndex.CharacterLocation onlyTargetLocation = null;
for (CharacterIndex.CharacterLocation characterLocation : toRet.data_)
if (battlecryOrigin.getBattlecryFilter().targetMatches(PlayerSide.CURRENT_PLAYER, this, characterLocation.getPlayerSide(), characterLocation.getIndex(), toRet.data_)) {
child = new HearthTreeNode(toRet.data_.deepCopy());
origin = child.data_.getCharacter(PlayerSide.CURRENT_PLAYER, originCharacterIndex);
child = origin.useTargetableBattlecry(characterLocation.getPlayerSide(), characterLocation.getIndex(), child);
if (child != null) {
children.add(child);
++numTargets;
onlyTargetLocation = characterLocation;
}

if (numTargets > 1) {
ArrayList<HearthTreeNode> children = new ArrayList<>();
for (CharacterIndex.CharacterLocation characterLocation : toRet.data_) {
if (battlecryOrigin.getBattlecryFilter().targetMatches(PlayerSide.CURRENT_PLAYER, this, characterLocation.getPlayerSide(), characterLocation.getIndex(), toRet.data_)) {
child = new HearthTreeNode(toRet.data_.deepCopy());
origin = child.data_.getCharacter(PlayerSide.CURRENT_PLAYER, originCharacterIndex);
child = origin.useTargetableBattlecry(characterLocation.getPlayerSide(), characterLocation.getIndex(), child);
if (child != null) {
children.add(child);
}
}
}
toRet = this.createNodeWithChildren(toRet, children);
} else if (numTargets == 1) {
toRet = this.useTargetableBattlecry(onlyTargetLocation.getPlayerSide(), onlyTargetLocation.getIndex(), toRet);
}
toRet = this.createNodeWithChildren(toRet, children);
}

if (wasPlayed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class KnifeJugglerSpec extends CardSpec {
def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)
ret = ret.getChildren().get(0);

expect:
ret != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DeadlyShotSpec extends CardSpec {
def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)
ret = ret.getChildren().get(0);

expect:
ret != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BombLobberSpec extends CardSpec {
def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)
ret = ret.getChildren().get(0);

expect:
ret != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ShadowboxerSpec extends CardSpec {
def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)
ret = ret.getChildren().get(0);

expect:
ret != null
Expand Down Expand Up @@ -72,6 +73,7 @@ class ShadowboxerSpec extends CardSpec {
def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)
ret = ret.getChildren().get(0);

expect:
ret != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ShipsCannonSpec extends CardSpec {
def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)
ret = ret.getChildren().get(0);

expect:
ret != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FlamecannonSpec extends CardSpec {
def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)
ret = ret.getChildren().get(0);

expect:
ret != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class CoghammerSpec extends CardSpec {
def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)
ret = ret.getChildren().get(0);

expect:
ret != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class GlaivezookaSpec extends CardSpec {
def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)
ret = ret.getChildren().get(0);

expect:
ret != null
Expand Down
28 changes: 0 additions & 28 deletions src/test/java/com/hearthsim/test/minion/TestTheBlackKnight.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,6 @@ public void test1() throws HSException {

assertFalse(ret == null);

assertEquals(currentPlayer.getHand().size(), 0);
assertEquals(currentPlayer.getNumMinions(), 4);
assertEquals(waitingPlayer.getNumMinions(), 4);
assertEquals(currentPlayer.getMana(), 4);
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(), 3);
assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_3).getTotalHealth(), 6);
assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_4).getTotalHealth(), 6);

assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_1).getTotalHealth(), 1);
assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_2).getTotalHealth(), 4);
assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_3).getTotalHealth(), 2);
assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_4).getTotalHealth(), 7);

assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_1).getTotalAttack(), 4);
assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_2).getTotalAttack(), 3);
assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_3).getTotalAttack(), 7);
assertEquals(currentPlayer.getCharacter(CharacterIndex.MINION_4).getTotalAttack(), 6);

assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_1).getTotalAttack(), 3);
assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_2).getTotalAttack(), 5);
assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_3).getTotalAttack(), 2);
assertEquals(waitingPlayer.getCharacter(CharacterIndex.MINION_4).getTotalAttack(), 7);

assertEquals(board.numChildren(), 0);
currentPlayer = ret.data_.getCurrentPlayer();
waitingPlayer = ret.data_.getWaitingPlayer();
Expand Down

0 comments on commit 92be4d9

Please sign in to comment.