Search in sources :

Example 1 with JEasyFrame

use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.

the class EvoSequenceTest method visiPlay.

public static void visiPlay(GameState game, int[] seq) throws Exception {
    PlanetWarView view = new PlanetWarView(game);
    JEasyFrame frame = new JEasyFrame(view, "Sequence View: " + Arrays.toString(seq));
    for (int x : seq) {
        int[] a = new int[] { x, GameState.doNothing };
        game.next(a);
        view.update(game);
        Thread.sleep(100);
    }
}
Also used : JEasyFrame(utilities.JEasyFrame)

Example 2 with JEasyFrame

use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.

the class GameRunner method plotGameScores.

public LineChart plotGameScores() {
    LineChart lineChart = new LineChart();
    for (GameLog gameLog : gameLogs) {
        LinePlot linePlot = new LinePlot().setData(gameLog.scores).setRandomColor();
        lineChart.addLine(linePlot);
    }
    lineChart.xAxis = new LineChartAxis(new double[] { 0, nSteps / 2, nSteps });
    lineChart.setXLabel("Game Tick");
    lineChart.setYLabel("Score");
    String title = String.format("%s (%d) v. %s (%d)", p1.toString(), p1Wins, p2.toString(), p2Wins);
    lineChart.setTitle(title);
    lineChart.bg = Color.gray;
    lineChart.plotBG = Color.white;
    double[] scoreTics = new double[] { scores.min(), 0, scores.max() };
    // double[] scoreTics = new  double[]{-100, 0, 1000, 2000 }; // scores.max()};
    lineChart.yAxis = new LineChartAxis(scoreTics);
    new JEasyFrame(lineChart, "Game Scores");
    return lineChart;
}
Also used : LineChartAxis(plot.LineChartAxis) LinePlot(plot.LinePlot) JEasyFrame(utilities.JEasyFrame) LineChart(plot.LineChart)

Example 3 with JEasyFrame

use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.

the class PlayoutPlotter method startPlot.

/*
    just call this to initialise it at the start of a plot routine
     */
@Override
public PlayoutPlotter startPlot(int sequenceLength) {
    lineChart = new LineChart().setBG(Color.gray);
    lineChart.xAxis = new LineChartAxis(new double[] { 0, sequenceLength / 2, sequenceLength });
    lineChart.yAxis = new LineChartAxis(new double[] { -50, -25, 0, 25, 50 });
    lineChart.setYLabel("Expected Score");
    lineChart.setXLabel("Rollout Depth");
    lineChart.plotBG = Color.white;
    frame = new JEasyFrame(lineChart, "Fitness versus depth");
    scores = new StatSummary();
    linePlots = new ArrayList<>();
    return this;
}
Also used : StatSummary(utilities.StatSummary) JEasyFrame(utilities.JEasyFrame)

Example 4 with JEasyFrame

use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.

the class ScatterDataTest method main.

public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(new File(file));
    ScatterPlot scatterPlot = new ScatterPlot().setTitle("Modules");
    while (scanner.hasNext()) {
        String line = null;
        try {
            line = scanner.nextLine();
            // System.out.println("Line: " + line);
            Scanner data = new Scanner(line);
            data.next();
            String module = data.next();
            double x = data.nextDouble();
            double y = data.nextDouble();
            char ch = module.charAt(3);
            Color col = colors[ch - '4'];
            System.out.println(module + " : " + ch + " : " + col);
            // System.out.println(module + " " + x + " " + y);
            if (x < enrolmentLimit) {
                System.out.println("Skipped due to small enrolment");
            } else {
                scatterPlot.addPoint(new DataPoint(module, x, y).setColor(col));
                System.out.println("Added");
            }
            System.out.println();
        } catch (Exception e) {
            System.out.println("Skipping: " + line);
        }
    }
    // now get the points and create arrays for the correlation stats
    ArrayList<DataPoint> points = scatterPlot.points;
    double[] x = new double[points.size()];
    double[] y = new double[points.size()];
    for (int i = 0; i < x.length; i++) {
        x[i] = points.get(i).x;
        y[i] = points.get(i).y;
    }
    double correlation = Stats.correlation(x, y);
    double rSquared = correlation * correlation;
    LineChart chart = new LineChart(new Dimension(800, 800));
    chart.setScatterPlot(scatterPlot);
    chart.xAxis = new LineChartAxis(new double[] { 0, 100, 200, 300, 400, 500 });
    chart.yAxis = new LineChartAxis(new double[] { 2, 3, 4, 5 });
    chart.setXLabel("Enrolment").setYLabel("Module Rating");
    chart.setTitle(String.format("Correlation: %.2f, r squared: %.3f", correlation, rSquared));
    chart.saveImage("../data/", "EECS-ScatterPlot.png");
    new JEasyFrame(chart, "Module evaluation versus enrolment");
}
Also used : Scanner(java.util.Scanner) JEasyFrame(utilities.JEasyFrame) File(java.io.File)

Example 5 with JEasyFrame

use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.

the class RopeGameTestController method main.

public static void main(String[] args) throws Exception {
    // make a game state
    // make a view based on the state
    // figure out a way to update it
    // the idea is to provide a simple demo of the game
    RopeGameState gameState = new RopeGameState();
    RopeGameView view = new RopeGameView(gameState);
    JEasyFrame frame = new JEasyFrame(view, "Monkey Ball");
    Random random = new Random();
    // this is the delay per frame update, but also use it
    // as the basis of switching an anchor point on and off
    int delay = 40;
    Vector2d anchor = null;
    for (int i = 0; i < 5000; i++) {
        // // each time update
        // if ((i / 40) % 2 == 0) {
        // anchor = null;
        // } else {
        // // if it is null, make a new one at a Random location
        // // otherwise leave alone
        // int w = RopeGameState.width;
        // if (anchor == null) {
        // anchor = new Vector2d(w/4 + random.nextInt(w/2), w/5 + random.nextInt(w/3));
        // }
        // }
        gameState.update(view.anchor);
        view.repaint();
        Thread.sleep(delay);
    }
}
Also used : JEasyFrame(utilities.JEasyFrame) Random(java.util.Random) Vector2d(math.Vector2d)

Aggregations

JEasyFrame (utilities.JEasyFrame)30 Random (java.util.Random)9 StatSummary (utilities.StatSummary)8 LineChart (plot.LineChart)7 ElapsedTimer (utilities.ElapsedTimer)7 LineChartAxis (plot.LineChartAxis)6 EvoAlg (evodef.EvoAlg)5 SimpleRMHC (ga.SimpleRMHC)5 ElapsedCpuTimer (tools.ElapsedCpuTimer)5 Types (ontology.Types)4 AbstractPlayer (core.player.AbstractPlayer)3 ArrayList (java.util.ArrayList)3 Scanner (java.util.Scanner)3 LevelView (ntuple.LevelView)3 NTupleBanditEA (ntuple.NTupleBanditEA)3 LineGroup (plot.LineGroup)3 LinePlot (plot.LinePlot)3 View (asteroids.View)2 BattleView (battle.BattleView)2 Agent (controllers.singlePlayer.ea.Agent)2