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);
}
}
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;
}
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;
}
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");
}
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);
}
}
Aggregations