-
-
Save luan/2960994 to your computer and use it in GitHub Desktop.
Spiral Water Flood
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
# Dont work =( | |
class SpiralFlood: | |
def __init__(self): | |
self.tiles = [] | |
def spiralFlood(self, sx, sy, K, m): | |
x = y = 0 | |
dx = 0 | |
dy = -1 | |
i = 0 | |
while i < m and i < K*K: | |
if (-K/2 < x <= K/2) and (-K/2 < y <= K/2): | |
if 0 <= x + sx < 32 and 0 <= y + sy < 32: | |
# print (x + sx, y + sy) | |
self.tiles[x + sx][y + sy] = "#" | |
i += 1 | |
if x == y or (x < 0 and x == -y) or (x > 0 and x == 1-y): | |
dx, dy = -dy, dx | |
x, y = x+dx, y+dy | |
flood = SpiralFlood() | |
for i in range(32): | |
r = [] | |
for j in range(32): | |
r.append(".") | |
flood.tiles.append(r) | |
flood.spiralFlood(15,15,32,15) | |
for k in range(32): | |
print flood.tiles[i] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment