use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class CompletelyChargeAbilitiesHeuristicAnalyzer method analyze.
@Override
public float analyze(List<MoveResult> results) {
float r = 0;
MoveResult before = results.get(0);
MoveResult end = results.get(results.size() - 1);
String currentUID = before.getMove().getPlayerUID();
List<Card> cards = end.getState().activeEntities.get(currentUID);
List<Card> beforeCards = before.getState().activeEntities.get(currentUID);
for (Card card : cards) {
if (card.getRunProgress() == card.getRunRequirements()) {
// this is fully charged. was it charged before?
before.getState().activeEntities.get(currentUID);
for (Card beforeCard : beforeCards) {
if (beforeCard.getMatchID() == card.getMatchID() && beforeCard.getRunProgress() < beforeCard.getRunRequirements()) {
r = 1;
break;
}
}
}
}
return r;
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class DamageHeuristicAnalyzer method analyze.
@Override
public float analyze(List<MoveResult> results) {
float r = 0;
MoveResult before = results.get(0);
MoveResult end = results.get(results.size() - 1);
float beforeHealth = getTotalHealths(before);
float endHealth = getTotalHealths(end);
// r = (beforeHealth - endHealth) / getMaxHealth(before);
r = Math.min((beforeHealth - endHealth) / GOOD_AMOUNT_OF_DAMAGE * results.size(), 1);
return r;
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class SQLAPI method recordMatchData.
public int recordMatchData(MatchData data) {
System.out.println("[SERVER][MYSQL]: Recording Match Data");
Json json = new Json(JsonWriter.OutputType.json);
int r = 0;
try {
r = 0;
// Insert New Match Record
String sql = "INSERT INTO computer_combat.`match` (player1_uid, player2_uid, deck1_id, deck2_id, winner, starttime, endtime, packets_player1, packets_player2)\n" + "VALUES ('" + data.getPlayer1().getUID() + "' , '" + data.getPlayer2().getUID() + "' , " + data.getPlayer1().getActiveDeck().getID() + " , " + data.getPlayer2().getActiveDeck().getID() + " , " + (data.getWinner() ? 1 : 0) + " , " + "str_to_date('" + data.getStartTime().toString() + "', '%Y-%m-%d %H:%i:%s.%f'), " + "str_to_date('" + data.getEndTime().toString() + "', '%Y-%m-%d %H:%i:%s.%f')," + data.getRewards().get(data.getPlayer1().getUID()) + "," + data.getRewards().get(data.getPlayer2().getUID()) + "" + ");";
Statement statement = connection.createStatement();
int updates = statement.executeUpdate(sql);
// Get Generated Match ID
sql = "SELECT LAST_INSERT_ID();";
ResultSet results = statement.executeQuery(sql);
results.next();
int match_id = results.getInt(1);
for (int i = 0; i < data.getMoves().size(); i++) {
// Insert Move Results
List<MoveResult> moveResults = data.getMoveResults().get(i);
// Insert Move
sql = "INSERT INTO move (`data`, `match_id`, `move_number`) " + "VALUES (JSON_QUOTE('" + json.toJson(moveResults) + "')," + match_id + "," + (i + 1) + ");";
updates = statement.executeUpdate(sql);
r += updates;
}
return updates;
} catch (Exception e) {
e.printStackTrace();
return r;
}
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class DrawAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> r = new ArrayList<>();
UseAbilityMove abilityMove = (UseAbilityMove) move;
List<Card> cards = state.activeEntities.get(move.getPlayerUID());
Deck deck = state.decks.get(move.getPlayerUID());
List<Card> drawnCards = new ArrayList<>();
if (cards.size() < 4) {
if (this.cards == null) {
if (deck.size() > 0) {
Card s = deck.draw();
s.setOwnerUID(move.getPlayerUID());
cards.add(s);
drawnCards.add(s);
}
} else {
for (StateAnalyzer<Integer> card : this.cards) {
Card s = SQLAPI.getSingleton().getCardById(card.analyze(state, move), move.getPlayerUID());
s.setOwnerUID(move.getPlayerUID());
s.generateMatchID();
cards.add(s);
drawnCards.add(s);
}
}
}
List<MoveAnimation> animations = new ArrayList<>();
if (abilityMove.getCard().getID() == 0) {
state.computers.get(move.getPlayerUID()).setProgress(0);
} else {
for (Card card : state.activeEntities.get(move.getPlayerUID())) {
if (card.equals(abilityMove.getCard())) {
card.setProgress(0);
}
}
}
List<Card> drained = new ArrayList<>();
drained.add(((UseAbilityMove) (move)).getCard());
ConsumeProgressAnimation drainAnimation = new ConsumeProgressAnimation(move.getPlayerUID(), drained);
DrawAnimation drawAnimation = new DrawAnimation(move.getPlayerUID(), drawnCards);
for (Player player : state.players) {
if (player.getUID().equals(move.getPlayerUID())) {
state.currentPlayerMove = state.getOtherProfile(player.getUID());
}
}
animations.add(drainAnimation);
animations.add(drawAnimation);
MoveResult result = new MoveResult(move, MatchState.record(state), animations);
r.add(result);
return r;
}
use of com.janfic.games.computercombat.model.moves.MoveResult in project computercombat by janfic.
the class SwitchComponentsAbility method doAbility.
@Override
public List<MoveResult> doAbility(MatchState state, Move move) {
List<MoveResult> results = new ArrayList<>();
UseAbilityMove useAbility = (UseAbilityMove) move;
Component[][] newBoard = state.componentBoard;
Component a = useAbility.getSelectedComponents().get(0);
Component b = useAbility.getSelectedComponents().get(1);
Component bb = newBoard[b.getX()][b.getY()];
Component ba = newBoard[a.getX()][a.getY()];
bb.invalidate();
ba.invalidate();
ba.invalidateNeighbors();
bb.invalidateNeighbors();
List<Card> drained = new ArrayList<>();
drained.add(((UseAbilityMove) (move)).getCard());
List<MoveAnimation> anims = new ArrayList<>();
anims.add(new ConsumeProgressAnimation(move.getPlayerUID(), drained));
anims.add(new SwitchAnimation(bb, ba));
MoveResult r = new MoveResult(move, MatchState.record(state), anims);
List<MoveResult> collectCheckResults = state.results(move);
results.add(r);
results.addAll(collectCheckResults);
return results;
}
Aggregations