summaryrefslogtreecommitdiff
path: root/example-bots/pathing.py
diff options
context:
space:
mode:
Diffstat (limited to 'example-bots/pathing.py')
-rw-r--r--example-bots/pathing.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/example-bots/pathing.py b/example-bots/pathing.py
new file mode 100644
index 0000000..d537940
--- /dev/null
+++ b/example-bots/pathing.py
@@ -0,0 +1,40 @@
+import random
+
+def move_toward_closest_factory(whoami, state, rx, ry):
+ if state[rx, ry].allegiance != whoami and state[rx, ry].city == '+':
+ return 'P'
+ to_do = [
+ (rx + 1, ry, 'R'),
+ (rx - 1, ry, 'L'),
+ (rx, ry - 1, 'U'),
+ (rx, ry + 1, 'D')
+ ]
+ random.shuffle(to_do)
+ seen = []
+ while to_do:
+ (x, y, move) = to_do.pop(0)
+ if (x, y) in seen or state[x, y].city == 'X':
+ continue
+ seen.append((x, y))
+ if state[x, y].allegiance != whoami and state[x, y].city == '+':
+ return move
+ else:
+ to_add = [(x + 1, y, move),
+ (x - 1, y, move),
+ (x, y + 1, move),
+ (x, y - 1, move)]
+ random.shuffle(to_add)
+ to_do += to_add
+
+def calculate_orders(whoami, state):
+ orders = []
+
+ my_robots = state.robots_by_player[whoami]
+ for rx, ry, energy in my_robots:
+ move = move_toward_closest_factory(whoami, state, rx, ry)
+ if move and random.random() > 0.1:
+ orders.append(move)
+ else:
+ orders.append(random.choice('UDLRP'))
+
+ return orders