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