RLEParser
Reads Game of Life .rle files
Install
<dependency>
<groupId>io.github.robertograham</groupId>
<artifactId>rle-parser</artifactId>
<version>1.0.1</version>
</dependency>
Usage
glider.rle
#C This is a glider.
x = 3, y = 3
bo$2bo$3o!
import io.github.robertograham.rleparser.RleParser;
import io.github.robertograham.rleparser.domain.LiveCells;
import io.github.robertograham.rleparser.domain.PatternData;
import java.net.URISyntaxException;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) throws URISyntaxException {
PatternData patternData = RleParser.readPatternData(Main.class.getClassLoader().getResource("glider.rle").toURI());
System.out.println(IntStream.range(0, patternData.getMetaData().getHeight())
.mapToObj(patternData.getLiveCells()::filteredByY)
.map(filteredByY -> IntStream.range(0, patternData.getMetaData().getWidth())
.mapToObj(filteredByY::filteredByX)
.map(LiveCells::getCoordinates)
.map(coordinates -> coordinates.size() == 0 ? "." : "@")
.collect(Collectors.joining()))
.collect(Collectors.joining("\n")));
}
}
Prints:
.@.
..@
@@@