Search in sources :

Example 6 with MatchState

use of com.janfic.games.computercombat.model.match.MatchState 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 7 with MatchState

use of com.janfic.games.computercombat.model.match.MatchState in project computercombat by janfic.

the class ExtraTurnHeuristicAnalyzer method analyze.

@Override
public float analyze(List<MoveResult> results) {
    float extraMove = 0;
    MatchState lastState = results.get(results.size() - 1).getState();
    MatchState firstState = results.get(0).getState();
    boolean gainedExtra = lastState.currentPlayerMove.equals(firstState.currentPlayerMove);
    extraMove = gainedExtra ? 1 : 0;
    return extraMove;
}
Also used : MatchState(com.janfic.games.computercombat.model.match.MatchState)

Example 8 with MatchState

use of com.janfic.games.computercombat.model.match.MatchState in project computercombat by janfic.

the class ChargedAbilitiesHeuristicAnalyzer method analyze.

@Override
public float analyze(List<MoveResult> results) {
    MatchState oldState = results.get(0).getState();
    Map<String, List<Card>> activeEntities = oldState.activeEntities;
    String playerUid = results.get(0).getMove().getPlayerUID();
    List<Card> activeCards = activeEntities.get(playerUid);
    Integer oldRunProgress = 0;
    Integer totalRunRequirements = 0;
    for (Card activeCard : activeCards) {
        oldRunProgress += activeCard.getRunProgress();
        totalRunRequirements += activeCard.getRunRequirements();
    }
    MatchState endState = results.get(results.size() - 1).getState();
    Map<String, List<Card>> newActiveEntities = endState.activeEntities;
    List<Card> newActiveCards = newActiveEntities.get(playerUid);
    Integer newRunProgress = 0;
    for (Card newActiveCard : newActiveCards) {
        newRunProgress += newActiveCard.getRunProgress();
    }
    return Math.max(0, (newRunProgress - oldRunProgress) / Math.max(totalRunRequirements, 1));
}
Also used : MatchState(com.janfic.games.computercombat.model.match.MatchState) List(java.util.List) Card(com.janfic.games.computercombat.model.Card)

Aggregations

MatchState (com.janfic.games.computercombat.model.match.MatchState)8 Move (com.janfic.games.computercombat.model.moves.Move)4 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)4 Component (com.janfic.games.computercombat.model.Component)3 Card (com.janfic.games.computercombat.model.Card)2 ComponentFilter (com.janfic.games.computercombat.util.ComponentFilter)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 Ability (com.janfic.games.computercombat.model.Ability)1 GameRules (com.janfic.games.computercombat.model.GameRules)1 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)1 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)1 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)1 Filter (com.janfic.games.computercombat.util.Filter)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1