Search in sources :

Example 16 with MoveResult

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;
}
Also used : MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Card(com.janfic.games.computercombat.model.Card)

Example 17 with MoveResult

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;
}
Also used : MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Example 18 with MoveResult

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;
    }
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Json(com.badlogic.gdx.utils.Json) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException)

Example 19 with MoveResult

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;
}
Also used : Player(com.janfic.games.computercombat.model.Player) MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) ArrayList(java.util.ArrayList) Deck(com.janfic.games.computercombat.model.Deck) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) Card(com.janfic.games.computercombat.model.Card) DrawAnimation(com.janfic.games.computercombat.model.animations.DrawAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Example 20 with MoveResult

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;
}
Also used : MoveAnimation(com.janfic.games.computercombat.model.moves.MoveAnimation) UseAbilityMove(com.janfic.games.computercombat.model.moves.UseAbilityMove) ArrayList(java.util.ArrayList) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component) ConsumeProgressAnimation(com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation) SwitchAnimation(com.janfic.games.computercombat.model.animations.SwitchAnimation) Card(com.janfic.games.computercombat.model.Card)

Aggregations

MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)25 ArrayList (java.util.ArrayList)16 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)15 Card (com.janfic.games.computercombat.model.Card)12 Component (com.janfic.games.computercombat.model.Component)7 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)7 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)5 MatchState (com.janfic.games.computercombat.model.match.MatchState)4 Move (com.janfic.games.computercombat.model.moves.Move)4 Ability (com.janfic.games.computercombat.model.Ability)2 Player (com.janfic.games.computercombat.model.Player)2 CollectAnimation (com.janfic.games.computercombat.model.animations.CollectAnimation)2 ReceiveDamageAnimation (com.janfic.games.computercombat.model.animations.ReceiveDamageAnimation)2 SpawnAnimation (com.janfic.games.computercombat.model.animations.SpawnAnimation)2 ComponentFilter (com.janfic.games.computercombat.util.ComponentFilter)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Array (com.badlogic.gdx.utils.Array)1 Json (com.badlogic.gdx.utils.Json)1 Deck (com.janfic.games.computercombat.model.Deck)1