about summary refs log tree commit diff homepage
path: root/brutalmaze/misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'brutalmaze/misc.py')
-rw-r--r--brutalmaze/misc.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/brutalmaze/misc.py b/brutalmaze/misc.py
index e6da56c..d26edf4 100644
--- a/brutalmaze/misc.py
+++ b/brutalmaze/misc.py
@@ -19,12 +19,15 @@
 
 __doc__ = 'Brutal Maze module for miscellaneous functions'
 
+from itertools import chain
 from math import degrees, cos, sin, pi
-from random import uniform
+from random import shuffle, uniform
 
 import pygame
 from pygame.gfxdraw import filled_polygon, aapolygon
 
+from .constants import ADJACENTS, CORNERS
+
 
 def round2(number):
     """Round a number to an int."""
@@ -69,6 +72,15 @@ def cosin(x):
     return cos(x) + sin(x)
 
 
+def around(x, y):
+    """Return grids around the given one in random order."""
+    a = [(x + i, y + j) for i, j in ADJACENTS]
+    shuffle(a)
+    c = [(x + i, y + j) for i, j in CORNERS]
+    shuffle(c)
+    return chain(a, c)
+
+
 def choices(d):
     """Choose a random key from a dict which has values being relative
     weights of the coresponding keys.