Last active
January 8, 2016 11:14
-
-
Save auscompgeek/f8695d7152e82e0fafc2 to your computer and use it in GitHub Desktop.
NyanFlip - An extension of BackFlip by Peter Ward (@flowblok). An example program is attached.
This file contains 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 | |
# NyanFlip - An extension of BackFlip by Peter Ward (flowblok). | |
# Implemented by David Vo (auscompgeek) and Jonathan Grigg. | |
import sys | |
ARROWS = '<V^>' | |
LEFT, DOWN, UP, RIGHT = ARROWS | |
def opp(direction): | |
if direction == UP: | |
return DOWN | |
if direction == DOWN: | |
return UP | |
if direction == LEFT: | |
return RIGHT | |
if direction == RIGHT: | |
return LEFT | |
def nyanflip(grid): | |
height = len(grid) | |
width = len(grid[0]) | |
x, y = 0, 0 | |
direction = RIGHT | |
score = 0 | |
while (0 <= x < width) and (0 <= y < height): | |
tile = grid[y][x] | |
if tile in ARROWS: | |
grid[y][x], direction = opp(direction), tile | |
elif tile == '\\': | |
if direction == DOWN: | |
direction = RIGHT | |
elif direction == UP: | |
direction = LEFT | |
elif direction == RIGHT: | |
direction = DOWN | |
elif direction == LEFT: | |
direction = UP | |
grid[y][x] = '/' | |
elif tile == '/': | |
if direction == DOWN: | |
direction = LEFT | |
elif direction == UP: | |
direction = RIGHT | |
elif direction == RIGHT: | |
direction = UP | |
elif direction == LEFT: | |
direction = DOWN | |
grid[y][x] = '\\' | |
elif tile == '+': | |
score += 1 | |
elif tile == '-': | |
score -= 1 | |
elif tile == '.': | |
print(score) | |
elif tile == ',': | |
sys.stdout.write(chr(score)) | |
if direction == UP: | |
y -= 1 | |
elif direction == DOWN: | |
y += 1 | |
elif direction == LEFT: | |
x -= 1 | |
elif direction == RIGHT: | |
x += 1 | |
def main(): | |
if len(sys.argv) > 1: | |
with open(sys.argv[1]) as f: | |
lines = f.read().split('\n\n')[0].split('\n') | |
else: | |
read = raw_input if sys.version_info[0] < 3 else input | |
try: | |
lines, line = [], read() | |
while line: | |
lines.append(line) | |
line = read() | |
except EOFError: | |
pass | |
nyanflip([list(x) for x in lines]) | |
if __name__ == '__main__': | |
main() |
This file contains 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
\++.+\\ \V | |
+ >++ <\ V+>\+.V | |
+VV^ .- \ V | |
>\ +<+ - ^-\-< | |
>\\<> -\ | |
>\ ^ >^- - | |
^ ^ ^ > -< |
read = raw_input if sys.version_info[0] < 3 else input
Many enterprise, such wow.
Apparently this was recycled for this year's NCSS ProgComp. Well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version history
This interpreter
v0: initial release
v1: added README and
*
checkpointv2: refactor to allow stepping through the program
v3: added
~
checkpointThe language
v-1: BackFlip
v0: as described for NCSS 2014 ProgComp
v1: added
,
checkpointv2: added
*
checkpointv3: added
~
checkpoint