+from server.config.world_data import world_db
+from server.utils import rand
+
+
+def is_neighbor(coordinates, type):
+ y = coordinates[0]
+ x = coordinates[1]
+ length = world_db["MAP_LENGTH"]
+ ind = y % 2
+ diag_west = x + (ind > 0)
+ diag_east = x + (ind < (length - 1))
+ pos = (y * length) + x
+ if (y > 0 and diag_east
+ and type == chr(world_db["MAP"][pos - length + ind])) \
+ or (x < (length - 1)
+ and type == chr(world_db["MAP"][pos + 1])) \
+ or (y < (length - 1) and diag_east
+ and type == chr(world_db["MAP"][pos + length + ind])) \
+ or (y > 0 and diag_west
+ and type == chr(world_db["MAP"][pos - length - (not ind)])) \
+ or (x > 0
+ and type == chr(world_db["MAP"][pos - 1])) \
+ or (y < (length - 1) and diag_west
+ and type == chr(world_db["MAP"][pos + length - (not ind)])):
+ return True
+ return False
+
+def new_pos():
+ length = world_db["MAP_LENGTH"]
+ y = rand.next() % length
+ x = rand.next() % length
+ return y, x, (y * length) + x
+