Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findNeighbors(width, height, tile):
- width = width
- height = height
- tile = tile
- row = (tile - 1) // width
- col = (tile - 1) % width
- tile1 = tile - width - 1
- tile2 = tile - width
- tile3 = tile - width + 1
- tile4 = tile - 1
- tile5 = tile + 1
- tile6 = tile + width - 1
- tile7 = tile + width
- tile8 = tile + width + 1
- if width * height == 1:
- return ""
- elif width * height == 2:
- if tile == 1:
- return "2"
- else:
- return "1"
- else:
- if row == 0:
- if col == 0:
- return str(tile5) + " " + str(tile7) + " " + str(tile8) + " "
- if col == width - 1:
- return str(tile4) + " " + str(tile6) + " " + str(tile7) + " "
- else:
- return str(tile4) + " " + str(tile5) + " " + str(tile6) + " " + str(tile7) + " " + str(tile8) + " "
- elif row == height - 1:
- if col == 0:
- return str(tile2) + " " + str(tile3) + " " + str(tile5) + " "
- if col == width - 1:
- return str(tile1) + " " + str(tile2) + " " + str(tile4) + " "
- else:
- return str(tile1) + " " + str(tile2) + " " + str(tile3) + " " + str(tile4) + " " + str(tile5) + " "
- elif col == 0:
- return str(tile2) + " " + str(tile3) + " " + str(tile5) + " " + str(tile7) + " " + str(tile8) + " "
- elif col == width - 1:
- return str(tile1) + " " + str(tile2) + " " + str(tile4) + " " + str(tile6) + " " + str(tile7) + " "
- else:
- return str(tile1) + " " + str(tile2) + " " + str(tile3) + " " + str(tile4) + " " + str(tile5) + " " + str(tile6) + " " + str(tile7) + " " + str(tile8) + " "
- #END YOUR CODE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement