From 9aedbb911e1596f30229469a53e56cf5c1056c97 Mon Sep 17 00:00:00 2001 From: Peter Ward Date: Thu, 2 Aug 2012 23:45:14 +1000 Subject: more sections --- docs/random_avoid.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 docs/random_avoid.py (limited to 'docs/random_avoid.py') 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) -- cgit v1.2.3