Search in sources :

Example 1 with LevelView

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));
}
Also used : LevelView(ntuple.LevelView) JEasyFrame(utilities.JEasyFrame)

Example 2 with LevelView

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();
        }
    }
}
Also used : Scanner(java.util.Scanner) LevelView(ntuple.LevelView) JEasyFrame(utilities.JEasyFrame) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with LevelView

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;
}
Also used : Scanner(java.util.Scanner) LevelView(ntuple.LevelView) JEasyFrame(utilities.JEasyFrame) FileInputStream(java.io.FileInputStream)

Aggregations

LevelView (ntuple.LevelView)3 JEasyFrame (utilities.JEasyFrame)3 FileInputStream (java.io.FileInputStream)2 Scanner (java.util.Scanner)2 File (java.io.File)1