use of com.janfic.games.computercombat.model.animations.CollectAnimation in project computercombat by janfic.
the class MatchState method results.
public List<MoveResult> results(Move move) {
List<MoveResult> results = new ArrayList<>();
boolean extraTurn = false;
while (isInvalidBoard() || getMatches().isEmpty() == false) {
// Save Old State
// Update
update();
// Collect Components
Map<Integer, List<Component>> collected = collectComponents();
Map<Component, Card> progress = new HashMap<>();
CollectAnimation collectAnimation = new CollectAnimation(collected, progress);
progress(collectAnimation);
// Attack
boolean attack = false;
for (Integer integer : collected.keySet()) {
for (Component component : collected.get(integer)) {
if (component.getColor() == 5) {
attack = true;
break;
}
}
}
if (attack && activeEntities.get(currentPlayerMove).isEmpty() == false) {
results.addAll(attack(move));
}
// Remove
for (Integer matchNumber : collected.keySet()) {
for (Component component : collected.get(matchNumber)) {
this.componentBoard[component.getX()][component.getY()].changeColor(0);
}
}
// Cascade
// This can be optimized by storing collected components
CascadeAnimation cascadeAnimation = new CascadeAnimation(cascade());
List<MoveAnimation> moveAnimation = new ArrayList<>();
moveAnimation.add(collectAnimation);
moveAnimation.add(cascadeAnimation);
for (Integer integer : collected.keySet()) {
if (collected.get(integer).size() >= 4) {
extraTurn = true;
}
}
MoveResult result = new MoveResult(move, MatchState.record(this), moveAnimation);
results.add(result);
}
if (extraTurn == false && results.size() > 0) {
MoveResult last = results.get(results.size() - 1);
last.getState().currentPlayerMove = last.getState().getOtherProfile(last.getState().currentPlayerMove);
this.currentPlayerMove = last.getState().currentPlayerMove;
}
return results;
}
use of com.janfic.games.computercombat.model.animations.CollectAnimation in project computercombat by janfic.
the class ComponentsCollectedHeuristicAnalyzer method analyze.
@Override
public float analyze(List<MoveResult> results) {
float maxValue = results.size() * GOOD_NUMBER_OF_COMPONENTS;
Integer totalComponentsCollected = 0;
for (MoveResult result : results) {
List<MoveAnimation> animations = result.getAnimations();
for (MoveAnimation animation : animations) {
if (animation instanceof CollectAnimation) {
CollectAnimation collectAnimation = (CollectAnimation) animation;
Integer componentsCollected = collectAnimation.getAllComponents().size();
totalComponentsCollected += componentsCollected;
}
}
}
return Math.min((totalComponentsCollected / maxValue), 1);
}
Aggregations