use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class CardToFrontAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
UseAbilityMove useAbilityMove = (UseAbilityMove) move;
MoveAnimation consume = Ability.consumeCardProgress(state, move);
List<Card> toFront = new ArrayList<>();
toFront.addAll(useAbilityMove.getSelectedSoftwares());
for (Card card : useAbilityMove.getSelectedSoftwares()) {
int cardIndex = state.activeEntities.get(card.getOwnerUID()).indexOf(card);
Card newStateCard = state.activeEntities.get(card.getOwnerUID()).get(cardIndex);
state.activeEntities.get(card.getOwnerUID()).remove(cardIndex);
state.activeEntities.get(card.getOwnerUID()).add(0, newStateCard);
}
state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
List<MoveAnimation> animations = new ArrayList<>();
animations.add(consume);
animations.add(new CardToFrontAnimation(toFront));
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 ChangeDefenseAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
String currentUID = move.getPlayerUID();
String opponentUID = state.getOtherProfile(state.currentPlayerMove);
List<MoveAnimation> animation = new ArrayList<>();
MoveAnimation consume = Ability.consumeCardProgress(state, move);
animation.add(consume);
for (Card card : state.getAllCards()) {
if (cardFilter.filter(card, state, move)) {
int amount = this.amount.analyze(state, move);
card.changeArmor(amount);
animation.add(new ChangeStatAnim("armor", amount, card, card.getOwnerUID()));
}
}
state.currentPlayerMove = state.getOtherProfile(state.currentPlayerMove);
MoveResult result = new MoveResult(move, MatchState.record(state), animation);
results.add(result);
return results;
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class DestroyCardAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
List<MoveAnimation> animations = new ArrayList<>();
List<Card> removed = new ArrayList<>();
for (Card card : destroyed) {
for (Card c : state.activeEntities.get(card.getOwnerUID())) {
if (c.equals(card)) {
removed.add(c);
List<Card> destroy = new ArrayList<>();
destroy.add(c);
animations.add(new DestroyCardAnimation(c.getOwnerUID(), destroy));
}
}
}
for (Card card : removed) {
state.activeEntities.get(card.getOwnerUID()).remove(card);
}
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 HeuristicBotPlayer method getMove.
@Override
public Move getMove() {
List<Move> moves = GameRules.getAvailableMoves(currentState);
Collections.shuffle(moves);
for (Move move : moves) {
long startTime = System.currentTimeMillis();
double moveSum = 0;
// Repeat move and find average score
for (int j = 0; j < MOVE_TRIES; j++) {
List<MoveResult> results = new ArrayList<>();
try {
results = GameRules.makeMove((MatchState) currentState.clone(), move);
double totalScore = 0;
for (int i = 0; i < priorityList.size(); i++) {
HeuristicAnalyzer analyzer = priorityList.get(i);
double baseScore = analyzer.analyze(results);
double priorityScalar = Math.pow(2, i);
double priorityScore = priorityScalar * baseScore;
totalScore += priorityScore;
}
moveSum += totalScore;
} catch (Exception e) {
e.printStackTrace();
}
}
double moveAverage = moveSum / MOVE_TRIES;
move.setValue(moveAverage);
long endTime = System.currentTimeMillis();
System.out.println("TIME: " + ((endTime - startTime) / 1000f));
}
moves.sort(new MoveValueComparator());
return moves.get(0);
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class ChargeAbilitiesHeuristicAnalyzer method analyze.
@Override
public float analyze(List<MoveResult> results) {
float r = 0;
MoveResult before = results.get(0);
MoveResult end = results.get(results.size() - 1);
r = (getCharges(end) - getCharges(before)) / getMaxCharges(before);
return r;
}
Aggregations