Search in sources :

Example 6 with MoveResult

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

the class TransformCardAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    List<MoveAnimation> animations = new ArrayList<>();
    MoveAnimation consumeProgress = Ability.consumeCardProgress(state, move);
    List<Card> old = new ArrayList<>();
    List<Card> newC = new ArrayList<>();
    for (CardFilter filter : oldCards) {
        for (String uid : state.activeEntities.keySet()) {
            for (int i = 0; i < state.activeEntities.get(uid).size(); i++) {
                Card oldCard = state.activeEntities.get(uid).get(i);
                if (filter.filter(oldCard, state, move)) {
                    Card newCard = SQLAPI.getSingleton().getCardById(newCards.get(oldCards.indexOf(filter)), oldCard.getOwnerUID());
                    newCard.generateMatchID();
                    state.activeEntities.get(uid).set(i, newCard);
                    old.add(oldCard);
                    newC.add(newCard);
                }
            }
        }
    }
    if (consumeProgress != null) {
        animations.add(consumeProgress);
    }
    animations.add(new TransformCardAnimation(old, newC));
    state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    results.add(result);
    return results;
}
Also used : CardFilter(com.janfic.games.computercombat.util.CardFilter) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) TransformCardAnimation(com.janfic.games.computercombat.model.animations.TransformCardAnimation) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card)

Example 7 with MoveResult

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

the class TransformComponentsAbility method doAbility.

@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
    List<MoveResult> results = new ArrayList<>();
    Component[][] board = state.getComponentBoard();
    List<MoveAnimation> animations = new ArrayList<>();
    MoveAnimation consumeProgress = Ability.consumeCardProgress(state, move);
    List<Component> originalComponents = new ArrayList<>(), newComponents = new ArrayList<>();
    for (Component[] components : board) {
        for (Component component : components) {
            if (filter.filter(component, state, move)) {
                int randomIndex = (int) (Math.random() * transformTypes.size());
                Component c = new Component(transformTypes.get(randomIndex), component.getX(), component.getY());
                originalComponents.add(new Component(component));
                newComponents.add(c);
                board[component.getX()][component.getY()].changeColor(transformTypes.get(randomIndex));
                board[component.getX()][component.getY()].invalidate();
                board[component.getX()][component.getY()].invalidateNeighbors();
            }
        }
    }
    animations.add(consumeProgress);
    animations.add(new SpawnAnimation(originalComponents, newComponents));
    MoveResult result = new MoveResult(move, MatchState.record(state), animations);
    List<MoveResult> afterMove = state.results(move);
    results.add(result);
    results.addAll(afterMove);
    return results;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component) SpawnAnimation(com.janfic.games.computercombat.model.animations.SpawnAnimation)

Example 8 with MoveResult

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

the class IncreaseComponentTypeHeuristicAnalyzer method analyze.

@Override
public float analyze(List<MoveResult> results) {
    float r = 0;
    MoveResult start = results.get(0);
    MoveResult end = results.get(results.size() - 1);
    ComponentFilter filter = new ComponentFilter() {

        @Override
        public boolean filter(Component component, MatchState state, Move move) {
            return component.getColor() == color;
        }
    };
    int endAmount = end.getState().countComponents(filter, end.getMove());
    int startAmount = start.getState().countComponents(filter, start.getMove());
    r = Math.min(Math.max(0, (endAmount - startAmount) / 3f), 1);
    return r;
}
Also used : Move(com.janfic.games.computercombat.model.moves.Move) ComponentFilter(com.janfic.games.computercombat.util.ComponentFilter) MatchState(com.janfic.games.computercombat.model.match.MatchState) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component)

Example 9 with MoveResult

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

the class KeepComponentTypeHeuristicAnalyzer method analyze.

@Override
public float analyze(List<MoveResult> results) {
    float r = 0;
    MoveResult end = results.get(results.size() - 1);
    ComponentFilter filter = new ComponentFilter() {

        @Override
        public boolean filter(Component component, MatchState state, Move move) {
            return component.getColor() == color;
        }
    };
    int amount = end.getState().countComponents(filter, end.getMove());
    r = Math.min(amount / 25f, 1);
    return r;
}
Also used : Move(com.janfic.games.computercombat.model.moves.Move) ComponentFilter(com.janfic.games.computercombat.util.ComponentFilter) MatchState(com.janfic.games.computercombat.model.match.MatchState) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component)

Example 10 with MoveResult

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

the class GameRules method makeMove.

public static List<MoveResult> makeMove(MatchState originalState, Move move) {
    List<MoveResult> results;
    if (move instanceof UseAbilityMove) {
        UseAbilityMove m = (UseAbilityMove) move;
        m.getCard().setAbility(Ability.getAbilityFromCode(m.getCard().getAbility()));
        results = m.doMove(originalState);
    } else {
        results = move.doMove(originalState);
    }
    return results;
}
Also used : UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) 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