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