use of ntuple.LevelView in project SimpleAsteroids by ljialin.
the class EvolveMarioLevelTest method update.
@Override
public void update(EvolutionLogger logger, int[] solution, double fitness) {
if (logger.nEvals() % freq != 0)
return;
if (levelFrame == null) {
// set them both up
levelView = new LevelView(LevelView.toRect(solution, imageWidth, imageHeight));
levelView.setColorMap(MarioReader.tileColors);
levelFrame = new JEasyFrame(levelView, "Title");
}
levelView.setTiles(solution);
levelFrame.setTitle(String.format("Evals: %d;\t fitness: %.3f", logger.nEvals(), fitness));
}
use of ntuple.LevelView in project SimpleAsteroids by ljialin.
the class MarioReader method showLevels.
public static void showLevels() throws Exception {
// String inputFile = "data/mario/example.txt";
String inputDirectory = "data/mario/levels/";
String outputFile = "data/mario/example.json";
// need to iterate over all the files in a directory
File file = new File(inputDirectory);
String[] fileList = file.list();
for (String inputFile : fileList) {
try {
System.out.println("Reading: " + inputFile);
int[][] level = readLevel(new Scanner(new FileInputStream(inputDirectory + inputFile)));
LevelView levelView = new LevelView(flip(level)).setColorMap(tileColors).setCellSize(10);
new JEasyFrame(levelView, inputFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of ntuple.LevelView in project SimpleAsteroids by ljialin.
the class EvolveMarioLevelTest method getAndShowLevel.
public static int[][] getAndShowLevel(boolean show) throws Exception {
String inputFile = "data/mario/levels/mario-2-1.txt";
System.out.println("Reading: " + inputFile);
int[][] level = flip(readLevel(new Scanner(new FileInputStream(inputFile))));
level = border(level);
if (show) {
LevelView levelView = new LevelView(level).setColorMap(tileColors).setCellSize(10);
new JEasyFrame(levelView, inputFile);
}
return level;
}
Aggregations