Created
July 3, 2017 18:17
-
-
Save vskrachkov/df3b503d6f9d3b8ee7cac179d2f98d87 to your computer and use it in GitHub Desktop.
Get first not empty coordinates
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
def create_all_positions(max_x, max_y): | |
all_positions = list() | |
for row in xrange(1, max_y+1): | |
all_positions.append([(col, row) for col in xrange(1, max_x+1)]) | |
return all_positions | |
def get_next_empty(all_positions, used_positions): | |
for row in all_positions: | |
for position in row: | |
if position not in used_positions: | |
return position | |
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
from n2 import create_all_positions, get_next_empty | |
max_x, max_y = 400, 400 | |
used_positions = [ | |
(1, 1), (2, 1), (3, 1), | |
(1, 2), (2, 2), | |
(1, 3), (2, 3), | |
] | |
next_position = (4, 1) | |
all_positions = create_all_positions(max_x, max_y) | |
print 'all positions: %s' % all_positions | |
print 'must be: ' | |
print next_position | |
print 'returns: ' | |
returned = get_next_empty(all_positions, used_positions) | |
print returned | |
assert next_position == returned |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment