Search in sources :

Example 1 with MatchState

use of com.janfic.games.computercombat.model.match.MatchState in project computercombat by janfic.

the class MatchScreen method initializeStage.

public void initializeStage(Message matchStateData) {
    MatchState state = json.fromJson(MatchState.class, matchStateData.getMessage());
    this.matchData.initializeState(state);
    Component[][] componentBoard = this.matchData.getCurrentState().componentBoard;
    board = new Board(skin, matchData, game, animation);
    for (int x = 0; x < componentBoard.length; x++) {
        for (int y = 0; y < componentBoard[x].length; y++) {
            board.addComponent(new ComponentActor(this.componentAtlas, componentBoard[x][y]), x, y);
        }
    }
    String currentUID = game.getCurrentProfile().getUID();
    String opponentUID = matchData.getCurrentState().getOtherProfile(game.getCurrentProfile().getUID());
    this.softwareActors.put(currentUID, new ArrayList<>());
    this.softwareActors.put(opponentUID, new ArrayList<>());
    this.computerActors.put(currentUID, new ComputerActor(skin, game, matchData.getCurrentState().computers.get(currentUID)));
    this.computerActors.put(opponentUID, new ComputerActor(skin, game, matchData.getCurrentState().computers.get(opponentUID)));
    for (String string : computerActors.keySet()) {
        computerActors.get(string).setCardsLeft(matchData.getCurrentState().decks.get(string).getStack().size());
    }
    for (String string : state.activeEntities.keySet()) {
        for (Card card : state.activeEntities.get(string)) {
            SoftwareActor a = new SoftwareActor(skin, !string.equals(game.getCurrentProfile().getUID()), card, game);
            softwareActors.get(string).add(a);
        }
    }
    Table table = new Table();
    leftPanel = new BorderedGrid(skin);
    leftPanel.pad(7);
    leftPanel.top();
    leftPanel.defaults().space(2);
    leftPanel.add(computerActors.get(game.getCurrentProfile().getUID())).expandY().growX().bottom();
    rightPanel = new BorderedGrid(skin);
    rightPanel.pad(7);
    rightPanel.top();
    rightPanel.defaults().space(2);
    rightPanel.add(computerActors.get(matchData.getCurrentState().getOtherProfile(game.getCurrentProfile().getUID()))).expandY().growX().bottom();
    buttons = new Panel(skin);
    buttons.add(new Label(game.getCurrentProfile().getName() + " vs. " + matchData.getOpponentName(), skin));
    infoPanel = new BorderedGrid(skin);
    infoPanel.setSize(220, 43);
    info = new Panel(skin);
    infoLabel = new Label("", skin);
    infoLabel.setFontScale(0.5f);
    infoLabel.setAlignment(Align.center);
    info.add(infoLabel).grow();
    infoPanel.add(info).grow();
    table.setFillParent(true);
    Table middleSection = new Table();
    middleSection.add(buttons).growX().height(20).colspan(3).row();
    middleSection.add(new Image(skin, "board_collector_left")).growX().top().padTop(7);
    Table middle = new Table();
    middle.add(board).row();
    middle.add(infoPanel).grow().row();
    middleSection.add(middle).growY();
    middleSection.add(new Image(skin, "board_collector_right")).growX().top().padTop(7).row();
    leftPanel.setZIndex(10);
    middleSection.setZIndex(0);
    rightPanel.setZIndex(10);
    table.add(leftPanel).pad(1, 0, 1, 0).grow().left();
    table.add(middleSection).top().growY();
    table.add(rightPanel).pad(1, 0, 1, 0).grow().right();
    mainStage.addActor(table);
    buildPanels();
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) MatchState(com.janfic.games.computercombat.model.match.MatchState)

Example 2 with MatchState

use of com.janfic.games.computercombat.model.match.MatchState 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;
}
Also used : Move(com.janfic.games.computercombat.model.moves.Move) ComponentFilter(com.janfic.games.computercombat.util.ComponentFilter) MatchState(com.janfic.games.computercombat.model.match.MatchState) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component)

Example 3 with MatchState

use of com.janfic.games.computercombat.model.match.MatchState 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;
}
Also used : Move(com.janfic.games.computercombat.model.moves.Move) ComponentFilter(com.janfic.games.computercombat.util.ComponentFilter) MatchState(com.janfic.games.computercombat.model.match.MatchState) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult) Component(com.janfic.games.computercombat.model.Component)

Example 4 with MatchState

use of com.janfic.games.computercombat.model.match.MatchState in project computercombat by janfic.

the class GameRules method shuffleBoard.

public static MatchState shuffleBoard(MatchState state) {
    try {
        MatchState nextState = (MatchState) state.clone();
        Component[][] components = nextState.getComponentBoard();
        while (areAvailableComponentMatches(nextState).isEmpty() == false) {
            List<Component> componentList = new ArrayList<>();
            for (Component[] component : components) {
                for (Component c : component) {
                    componentList.add(c);
                }
            }
            Collections.shuffle(componentList);
            int index = 0;
            for (int x = 0; x < components.length; x++) {
                for (int y = 0; y < components[x].length; y++) {
                    components[x][y] = componentList.get(index);
                    index++;
                }
            }
        }
        return nextState;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : MatchState(com.janfic.games.computercombat.model.match.MatchState)

Example 5 with MatchState

use of com.janfic.games.computercombat.model.match.MatchState 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);
}
Also used : Move(com.janfic.games.computercombat.model.moves.Move) ArrayList(java.util.ArrayList) MatchState(com.janfic.games.computercombat.model.match.MatchState) MoveResult(com.janfic.games.computercombat.model.moves.MoveResult)

Aggregations

MatchState (com.janfic.games.computercombat.model.match.MatchState)8 Move (com.janfic.games.computercombat.model.moves.Move)4 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)4 Component (com.janfic.games.computercombat.model.Component)3 Card (com.janfic.games.computercombat.model.Card)2 ComponentFilter (com.janfic.games.computercombat.util.ComponentFilter)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 Ability (com.janfic.games.computercombat.model.Ability)1 GameRules (com.janfic.games.computercombat.model.GameRules)1 ConsumeProgressAnimation (com.janfic.games.computercombat.model.animations.ConsumeProgressAnimation)1 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)1 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)1 Filter (com.janfic.games.computercombat.util.Filter)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1