Search in sources :

Example 21 with MoveResult

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;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) AttackAnimation(com.janfic.games.computercombat.model.animations.AttackAnimation) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card)

Example 22 with MoveResult

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;
}
Also used : Component(com.janfic.games.computercombat.model.Component) GameRules(com.janfic.games.computercombat.model.GameRules) MatchState(com.janfic.games.computercombat.model.match.MatchState) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) Ability(com.janfic.games.computercombat.model.Ability) Filter(com.janfic.games.computercombat.util.Filter) Collectors(java.util.stream.Collectors) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) ArrayList(java.util.ArrayList) List(java.util.List) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) Stream(java.util.stream.Stream) Map(java.util.Map) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) Card(com.janfic.games.computercombat.model.Card) Collections(java.util.Collections) Move(com.janfic.games.computercombat.model.moves.Move) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component)

Example 23 with MoveResult

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;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ReceiveDamageAnimation(com.janfic.games.computercombat.model.animations.ReceiveDamageAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) Card(com.janfic.games.computercombat.model.Card)

Example 24 with MoveResult

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;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CollectAnimation(com.janfic.games.computercombat.model.animations.CollectAnimation) CascadeAnimation(com.janfic.games.computercombat.model.animations.CascadeAnimation) Card(com.janfic.games.computercombat.model.Card) ArrayList(java.util.ArrayList) List(java.util.List) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component)

Example 25 with MoveResult

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);
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) CollectAnimation(com.janfic.games.computercombat.model.animations.CollectAnimation) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Aggregations

MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)25 ArrayList (java.util.ArrayList)16 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)15 Card (com.janfic.games.computercombat.model.Card)12 Component (com.janfic.games.computercombat.model.Component)7 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)7 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)5 MatchState (com.janfic.games.computercombat.model.match.MatchState)4 Move (com.janfic.games.computercombat.model.moves.Move)4 Ability (com.janfic.games.computercombat.model.Ability)2 Player (com.janfic.games.computercombat.model.Player)2 CollectAnimation (com.janfic.games.computercombat.model.animations.CollectAnimation)2 ReceiveDamageAnimation (com.janfic.games.computercombat.model.animations.ReceiveDamageAnimation)2 SpawnAnimation (com.janfic.games.computercombat.model.animations.SpawnAnimation)2 ComponentFilter (com.janfic.games.computercombat.util.ComponentFilter)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Array (com.badlogic.gdx.utils.Array)1 Json (com.badlogic.gdx.utils.Json)1 Deck (com.janfic.games.computercombat.model.Deck)1