Search in sources :

Example 11 with MoveResult

use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.

the class CardToFrontAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    UseAbilityMove useAbilityMove = (UseAbilityMove) move;
    MoveAnimation consume = Ability.consumeCardProgress(state, move);
    List<Card> toFront = new ArrayList<>();
    toFront.addAll(useAbilityMove.getSelectedSoftwares());
    for (Card card : useAbilityMove.getSelectedSoftwares()) {
        int cardIndex = state.activeEntities.get(card.getOwnerUID()).indexOf(card);
        Card newStateCard = state.activeEntities.get(card.getOwnerUID()).get(cardIndex);
        state.activeEntities.get(card.getOwnerUID()).remove(cardIndex);
        state.activeEntities.get(card.getOwnerUID()).add(0, newStateCard);
    }
    state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
    List<MoveAnimation> animations = new ArrayList<>();
    animations.add(consume);
    animations.add(new CardToFrontAnimation(toFront));
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    results.add(result);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card) CardToFrontAnimation(com.janfic.games.computercombat.model.animations.CardToFrontAnimation)

Example 12 with MoveResult

use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.

the class ChangeDefenseAbility 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<MoveAnimation> animation = new ArrayList<>();
    MoveAnimation consume = Ability.consumeCardProgress(state, move);
    animation.add(consume);
    for (Card card : state.getAllCards()) {
        if (cardFilter.filter(card, state, move)) {
            int amount = this.amount.analyze(state, move);
            card.changeArmor(amount);
            animation.add(new ChangeStatAnim("armor", amount, card, card.getOwnerUID()));
        }
    }
    state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
    MoveResult result = new MoveResult(move, MatchState.record(state), animation);
    results.add(result);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ChangeStatAnim(com.janfic.games.computercombat.model.animations.ChangeStatAnim) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card)

Example 13 with MoveResult

use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.

the class DestroyCardAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    List<MoveAnimation> animations = new ArrayList<>();
    List<Card> removed = new ArrayList<>();
    for (Card card : destroyed) {
        for (Card c : state.activeEntities.get(card.getOwnerUID())) {
            if (c.equals(card)) {
                removed.add(c);
                List<Card> destroy = new ArrayList<>();
                destroy.add(c);
                animations.add(new DestroyCardAnimation(c.getOwnerUID(), destroy));
            }
        }
    }
    for (Card card : removed) {
        state.activeEntities.get(card.getOwnerUID()).remove(card);
    }
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    results.add(result);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) DestroyCardAnimation(com.janfic.games.computercombat.model.animations.DestroyCardAnimation) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card)

Example 14 with MoveResult

use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.

the class HeuristicBotPlayer method getMove.

@Override
public Move getMove() {
    List<Move> moves = GameRules.getAvailableMoves(currentState);
    Collections.shuffle(moves);
    for (Move move : moves) {
        long startTime = System.currentTimeMillis();
        double moveSum = 0;
        // Repeat move and find average score
        for (int j = 0; j < MOVE_TRIES; j++) {
            List<MoveResult> results = new ArrayList<>();
            try {
                results = GameRules.makeMove((MatchState) currentState.clone(), move);
                double totalScore = 0;
                for (int i = 0; i < priorityList.size(); i++) {
                    HeuristicAnalyzer analyzer = priorityList.get(i);
                    double baseScore = analyzer.analyze(results);
                    double priorityScalar = Math.pow(2, i);
                    double priorityScore = priorityScalar * baseScore;
                    totalScore += priorityScore;
                }
                moveSum += totalScore;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        double moveAverage = moveSum / MOVE_TRIES;
        move.setValue(moveAverage);
        long endTime = System.currentTimeMillis();
        System.out.println("TIME: " + ((endTime - startTime) / 1000f));
    }
    moves.sort(new MoveValueComparator());
    return moves.get(0);
}
Also used : Move(com.janfic.games.computercombat.model.moves.Move) ArrayList(java.util.ArrayList) MatchState(com.janfic.games.computercombat.model.match.MatchState) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Example 15 with MoveResult

use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.

the class ChargeAbilitiesHeuristicAnalyzer method analyze.

@Override
public float analyze(List<MoveResult> results) {
    float r = 0;
    MoveResult before = results.get(0);
    MoveResult end = results.get(results.size() - 1);
    r = (getCharges(end) - getCharges(before)) / getMaxCharges(before);
    return r;
}
Also used : 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