Skip to content

Instantly share code, notes, and snippets.

@jacobjoaquin
Last active December 27, 2015 15:09
Show Gist options
  • Save jacobjoaquin/7345318 to your computer and use it in GitHub Desktop.
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
#!/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