Last active
December 27, 2015 15:09
-
-
Save jacobjoaquin/7345318 to your computer and use it in GitHub Desktop.
Python script for converting a Sokoban XSB formatted ascii to a Sokovan RLE ascii. Usage example:
$ cat my-level.xsb | ./sokoban_xsb2rle.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import re | |
import sys | |
level = sys.stdin.read() | |
flat = [] | |
output = [] | |
for L in [L.rstrip().replace(' ', '-') for L in level.splitlines()]: | |
if len(L) > 0: | |
flat.append(L) | |
for g in [m.group() for m in re.finditer(r'(.)\1*', '|'.join(flat))]: | |
if len(g) >= 3: | |
output.append(str(len(g))) | |
output.append(g[0]) | |
else: | |
output.append(g) | |
print ''.join(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment