An open API service indexing awesome lists of open source software.

https://github.com/robertograham/rleparser

Parse .rle files (Game of Life)
https://github.com/robertograham/rleparser

gameoflife rle run-length-encoding

Last synced: 4 months ago
JSON representation

Parse .rle files (Game of Life)

Awesome Lists containing this project

README

        

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.robertograham/rle-parser/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.robertograham/rle-parser)
# RLEParser
Reads Game of Life .rle files

## Install
```xml

io.github.robertograham
rle-parser
1.0.1

```

## Usage
glider.rle
```
#C This is a glider.
x = 3, y = 3
bo$2bo$3o!
```
```java
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:
```
.@.
..@
@@@
```