Search in sources :

Example 1 with ComponentFilter

use of com.janfic.games.computercombat.util.ComponentFilter 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 2 with ComponentFilter

use of com.janfic.games.computercombat.util.ComponentFilter 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 3 with ComponentFilter

use of com.janfic.games.computercombat.util.ComponentFilter in project computercombat by janfic.

the class MatchScreen method playerUseAbilityMoveCheck.

private void playerUseAbilityMoveCheck() {
    for (SoftwareActor softwareActor : softwareActors.get(game.getCurrentProfile().getUID())) {
        if (softwareActor.activatedAbility()) {
            Ability ability = softwareActor.getSoftware().getAbility();
            if (isSelecting == false) {
                this.selectIndex = 0;
                selectedCards.clear();
                selectedComponents.clear();
                this.isSelecting = true;
            }
            if (ability.getSelectFilters().size() > 0) {
                this.currentSelectFilter = ability.getSelectFilters().get(selectIndex);
                if (this.currentSelectFilter instanceof ComponentFilter) {
                    if (!board.isSelecting()) {
                        board.startComponentSelection((ComponentFilter) this.currentSelectFilter);
                    }
                    if (board.didCompleteSelection()) {
                        selectedComponents.addAll(board.getSelected());
                        selectIndex++;
                        board.endComponentSelection();
                    }
                } else if (this.currentSelectFilter instanceof CardFilter) {
                    CardFilter filter = (CardFilter) this.currentSelectFilter;
                    for (String uid : this.softwareActors.keySet()) {
                        for (SoftwareActor sa : this.softwareActors.get(uid)) {
                            if (!sa.isSelecting()) {
                                if (!filter.filter(sa.getSoftware(), matchData.getCurrentState(), null)) {
                                    sa.setColor(Color.GRAY);
                                    sa.setTouchable(Touchable.disabled);
                                } else {
                                    sa.startSelection();
                                }
                            }
                            if (sa.isSelected()) {
                                this.selectedCards.add(sa);
                                selectIndex++;
                                for (String u : this.softwareActors.keySet()) {
                                    for (SoftwareActor s : this.softwareActors.get(u)) {
                                        s.endSelection();
                                        sa.setColor(Color.WHITE);
                                        sa.setTouchable(Touchable.enabled);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (selectIndex == ability.getSelectFilters().size()) {
                List<Component> components = new ArrayList<>();
                List<Card> cards = new ArrayList<>();
                for (ComponentActor selectedComponent : selectedComponents) {
                    components.add(selectedComponent.getComponent());
                }
                for (SoftwareActor selectedCard : selectedCards) {
                    cards.add(selectedCard.getSoftware());
                }
                UseAbilityMove move = new UseAbilityMove(game.getCurrentProfile().getUID(), softwareActor.getSoftware(), components, cards);
                softwareActor.setActivatedAbility(false);
                System.out.println("USED ABILITY MOVE");
                if (GameRules.getAvailableMoves(matchData.getCurrentState()).contains(move)) {
                    game.getServerAPI().sendMessage(new Message(Type.MOVE_REQUEST, json.toJson(move)));
                } else {
                    System.out.println("NOT VALID MOVE???");
                }
                this.isSelecting = false;
                this.selectIndex = -1;
                this.selectedCards.clear();
                this.selectedComponents.clear();
                for (String u : this.softwareActors.keySet()) {
                    for (SoftwareActor s : this.softwareActors.get(u)) {
                        s.endSelection();
                        s.setColor(Color.WHITE);
                        s.setTouchable(Touchable.enabled);
                    }
                }
            }
        }
    }
    ComputerActor computerActor = computerActors.get(game.getCurrentProfile().getUID());
    if (computerActor.activatedAbility()) {
        UseAbilityMove move = new UseAbilityMove(game.getCurrentProfile().getUID(), computerActor.getComputer(), new ArrayList<>(), new ArrayList<>());
        computerActor.setActivatedAbility(false);
        if (GameRules.getAvailableMoves(matchData.getCurrentState()).contains(move)) {
            game.getServerAPI().sendMessage(new Message(Type.MOVE_REQUEST, json.toJson(move)));
        }
    }
}
Also used : CardFilter(com.janfic.games.computercombat.util.CardFilter) Message(com.janfic.games.computercombat.network.Message) ComponentFilter(com.janfic.games.computercombat.util.ComponentFilter)

Example 4 with ComponentFilter

use of com.janfic.games.computercombat.util.ComponentFilter in project computercombat by janfic.

the class GameRules method generateMovesWithSelection.

private static List<UseAbilityMove> generateMovesWithSelection(int index, Card card, MatchState state, List<Component> selectedComponents, List<Card> selectedCards) {
    List<UseAbilityMove> moves = new ArrayList<>();
    String uid = state.currentPlayerMove;
    System.out.println(card);
    System.out.println(card.getAbility());
    List<Filter> selectFilters = card.getAbility().getSelectFilters();
    if (index >= selectFilters.size()) {
        List<Component> selectedComponentsClone = new ArrayList<>(selectedComponents);
        List<Card> selectedCardsClone = new ArrayList<>(selectedCards);
        moves.add(new UseAbilityMove(uid, card, selectedComponentsClone, selectedCardsClone));
    } else {
        Filter filter = selectFilters.get(index);
        if (filter instanceof ComponentFilter) {
            List<Component> sComps = new ArrayList<>(selectedComponents);
            List<Card> sCards = new ArrayList<>(selectedCards);
            List<Component> selectableComponents = state.getComponentsByFilter((ComponentFilter) filter, new UseAbilityMove(uid, card, sComps, sCards));
            for (Component selectableComponent : selectableComponents) {
                sComps.add(selectableComponent);
                moves.addAll(generateMovesWithSelection(index + 1, card, state, sComps, sCards));
                sComps.remove(sComps.size() - 1);
            }
        } else if (filter instanceof CardFilter) {
            List<Component> sComps = new ArrayList<>(selectedComponents);
            List<Card> sCards = new ArrayList<>(selectedCards);
            List<Card> selectableCards = state.getCardsByFilter((CardFilter) filter, new UseAbilityMove(uid, card, sComps, sCards));
            for (Card selectableCard : selectableCards) {
                sCards.add(selectableCard);
                moves.addAll(generateMovesWithSelection(index + 1, card, state, sComps, sCards));
                sCards.remove(sCards.size() - 1);
            }
        }
    }
    return moves;
}
Also used : CardFilter(com.janfic.games.computercombat.util.CardFilter) ComponentFilter(com.janfic.games.computercombat.util.ComponentFilter) CardFilter(com.janfic.games.computercombat.util.CardFilter) ComponentFilter(com.janfic.games.computercombat.util.ComponentFilter) Filter(com.janfic.games.computercombat.util.Filter) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove)

Aggregations

ComponentFilter (com.janfic.games.computercombat.util.ComponentFilter)4 Component (com.janfic.games.computercombat.model.Component)2 MatchState (com.janfic.games.computercombat.model.match.MatchState)2 Move (com.janfic.games.computercombat.model.moves.Move)2 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)2 CardFilter (com.janfic.games.computercombat.util.CardFilter)2 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)1 Message (com.janfic.games.computercombat.network.Message)1 Filter (com.janfic.games.computercombat.util.Filter)1