summaryrefslogtreecommitdiff
path: root/robots/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'robots/utils.py')
-rw-r--r--robots/utils.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/robots/utils.py b/robots/utils.py
index 4473a6b..544bec7 100644
--- a/robots/utils.py
+++ b/robots/utils.py
@@ -1,18 +1,35 @@
from random import sample
import time
+def add_spawns(map_, n_spawns):
+ available = []
+ for x, y, cell in iter_board(map_):
+ if cell != '*':
+ available.append((x, y))
+
+ spawns = sample(available, n_spawns)
+ for i, (x, y) in enumerate(spawns):
+ map_[y][x] = str(i)
+
def empty_map(width, height, n_spawns):
board = [['.'] * width for y in range(height)]
- all_positions = [
- (x, y)
- for x in range(width)
- for y in range(height)
+ add_spawns(board, n_spawns)
+ return board
+
+def border_map(width, height, n_spawns):
+ board = [
+ ['.'] * (width + 2)
+ for y in range(height + 2)
]
- spawns = sample(all_positions, n_spawns)
+ for x in range(width + 2):
+ board[0][x] = '*'
+ board[-1][x] = '*'
+ for y in range(height + 2):
+ board[y][0] = '*'
+ board[y][-1] = '*'
- for i, (x, y) in enumerate(spawns):
- board[y][x] = str(i)
+ add_spawns(board, n_spawns)
return board
def rate_limit(fps):