summaryrefslogtreecommitdiff
path: root/docs/random_avoid.py
diff options
context:
space:
mode:
authorPeter Ward <peteraward@gmail.com>2012-08-02 23:45:14 +1000
committerPeter Ward <peteraward@gmail.com>2012-08-02 23:45:14 +1000
commit9aedbb911e1596f30229469a53e56cf5c1056c97 (patch)
tree87f77458dd70c3d4232689b6d02d9fdf41a26804 /docs/random_avoid.py
parent6f2055925874e2c948e5672f3ad734b54b862032 (diff)
more sections
Diffstat (limited to 'docs/random_avoid.py')
-rw-r--r--docs/random_avoid.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/random_avoid.py b/docs/random_avoid.py
new file mode 100644
index 0000000..bf08eef
--- /dev/null
+++ b/docs/random_avoid.py
@@ -0,0 +1,26 @@
+from random import choice
+
+def random_avoid_bot(board, position):
+ x, y = position
+ height = len(board)
+ width = len(board[0])
+
+ valid_moves = []
+
+ left = board[y][(x - 1) % width]
+ if left == '.' or left == '*':
+ valid_moves.append('L')
+
+ right = board[y][(x + 1) % width]
+ if right == '.' or right == '*':
+ valid_moves.append('R')
+
+ up = board[(y - 1) % height][x]
+ if up == '.' or up == '*':
+ valid_moves.append('U')
+
+ down = board[(y + 1) % height][x]
+ if down == '.' or down == '*':
+ valid_moves.append('D')
+
+ return choice(valid_moves)