use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class AttackAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
String currentUID = move.getPlayerUID();
String opponentUID = state.getOtherProfile(state.currentPlayerMove);
List<Card> destroyed = new ArrayList<>();
List<MoveAnimation> animation = new ArrayList<>();
for (String key : attacks.keySet()) {
Array<Integer> attacked = attacks.get(key);
for (Integer c : attacked) {
Card att = state.getCardMyMatchID(Integer.parseInt(key));
if (att.getID() > 0) {
for (Card cardAttacked : state.activeEntities.get(opponentUID)) {
if (c == cardAttacked.getMatchID()) {
cardAttacked.recieveDamage(state.getCardMyMatchID(Integer.parseInt(key)).getAttack());
animation.add(new AttackAnimation(currentUID, opponentUID, attacks));
if (cardAttacked.isDead()) {
destroyed.add(cardAttacked);
}
break;
}
}
} else if (att.getID() == 0) {
Card cardAttacked = state.computers.get(opponentUID);
cardAttacked.recieveDamage(state.getCardMyMatchID(Integer.parseInt(key)).getAttack());
animation.add(new AttackAnimation(currentUID, opponentUID, attacks));
}
}
}
MoveResult result = new MoveResult(move, MatchState.record(state), animation);
results.add(result);
if (!destroyed.isEmpty()) {
DestroyCardAbility destroyAbility = new DestroyCardAbility(destroyed);
List<MoveResult> r = destroyAbility.doAbility(state, move);
results.addAll(r);
}
return results;
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class CollectAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
List<MoveAnimation> anim = new ArrayList<>();
anim.add(Ability.consumeCardProgress(state, move));
results.add(new MoveResult(move, MatchState.record(state), anim));
UseAbilityMove useAbility = (UseAbilityMove) move;
int index = state.activeEntities.get(useAbility.getPlayerUID()).indexOf(useAbility.getCard());
state.activeEntities.get(useAbility.getPlayerUID()).get(index).setProgress(0);
Stream<Component> components = state.getComponentsAsList().stream();
for (CollectFilter filter : filters) {
components = components.filter((c) -> {
return filter.filter(state, move, c);
});
}
List<Component> list = components.collect(Collectors.toList());
Collections.shuffle(list);
int count = amount.analyze(state, move);
list = list.subList(0, Math.min(count, list.size()));
Component[] c = list.toArray(new Component[0]);
for (Component component : c) {
component.getMatchNeighbors().add(-1);
}
List<MoveResult> result = state.results(move);
results.addAll(result);
return results;
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class DamageAllAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
UseAbilityMove abilityMove = (UseAbilityMove) move;
List<Card> destroyed = new ArrayList<>();
List<MoveAnimation> animation = new ArrayList<>();
int index = state.activeEntities.get(abilityMove.getCard().getOwnerUID()).indexOf(abilityMove.getCard());
state.activeEntities.get(abilityMove.getPlayerUID()).get(index).setProgress(0);
for (Card card : state.getAllCards()) {
if (filter == null || filter.filter(card, state, move)) {
int damage = amount.analyze(state, move);
animation.add(new ReceiveDamageAnimation(card, damage, card.getOwnerUID()));
card.recieveDamage(damage);
if (card.isDead()) {
destroyed.add(card);
}
}
}
state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
MoveResult result = new MoveResult(move, MatchState.record(state), animation);
results.add(result);
if (destroyed.isEmpty() == false) {
DestroyCardAbility destroyAbility = new DestroyCardAbility(destroyed);
List<MoveResult> r = destroyAbility.doAbility(state, move);
results.addAll(r);
}
List<Card> drained = new ArrayList<>();
drained.add(((UseAbilityMove) (move)).getCard());
results.get(0).getAnimations().add(0, new ConsumeProgressAnimation(move.getPlayerUID(), drained));
return results;
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class MatchState method results.
public List<MoveResult> results(Move move) {
List<MoveResult> results = new ArrayList<>();
boolean extraTurn = false;
while (isInvalidBoard() || getMatches().isEmpty() == false) {
// Save Old State
// Update
update();
// Collect Components
Map<Integer, List<Component>> collected = collectComponents();
Map<Component, Card> progress = new HashMap<>();
CollectAnimation collectAnimation = new CollectAnimation(collected, progress);
progress(collectAnimation);
// Attack
boolean attack = false;
for (Integer integer : collected.keySet()) {
for (Component component : collected.get(integer)) {
if (component.getColor() == 5) {
attack = true;
break;
}
}
}
if (attack && activeEntities.get(currentPlayerMove).isEmpty() == false) {
results.addAll(attack(move));
}
// Remove
for (Integer matchNumber : collected.keySet()) {
for (Component component : collected.get(matchNumber)) {
this.componentBoard[component.getX()][component.getY()].changeColor(0);
}
}
// Cascade
// This can be optimized by storing collected components
CascadeAnimation cascadeAnimation = new CascadeAnimation(cascade());
List<MoveAnimation> moveAnimation = new ArrayList<>();
moveAnimation.add(collectAnimation);
moveAnimation.add(cascadeAnimation);
for (Integer integer : collected.keySet()) {
if (collected.get(integer).size() >= 4) {
extraTurn = true;
}
}
MoveResult result = new MoveResult(move, MatchState.record(this), moveAnimation);
results.add(result);
}
if (extraTurn == false && results.size() > 0) {
MoveResult last = results.get(results.size() - 1);
last.getState().currentPlayerMove = last.getState().getOtherProfile(last.getState().currentPlayerMove);
this.currentPlayerMove = last.getState().currentPlayerMove;
}
return results;
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class ComponentsCollectedHeuristicAnalyzer method analyze.
@Override
public float analyze(List<MoveResult> results) {
float maxValue = results.size() * GOOD_NUMBER_OF_COMPONENTS;
Integer totalComponentsCollected = 0;
for (MoveResult result : results) {
List<MoveAnimation> animations = result.getAnimations();
for (MoveAnimation animation : animations) {
if (animation instanceof CollectAnimation) {
CollectAnimation collectAnimation = (CollectAnimation) animation;
Integer componentsCollected = collectAnimation.getAllComponents().size();
totalComponentsCollected += componentsCollected;
}
}
}
return Math.min((totalComponentsCollected / maxValue), 1);
}
Aggregations