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;
}
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;
}
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)));
}
}
}
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;
}
Aggregations