From 7daa5284f9eddf6d4b4e7838919e80ce25324bb0 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Sun, 25 Sep 2022 00:10:13 +1000 Subject: Lots of changes! --- example-bots/random_valid.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 example-bots/random_valid.py (limited to 'example-bots/random_valid.py') diff --git a/example-bots/random_valid.py b/example-bots/random_valid.py new file mode 100644 index 0000000..0a84b96 --- /dev/null +++ b/example-bots/random_valid.py @@ -0,0 +1,30 @@ +import random + +def calculate_orders(whoami, state): + orders = [] + + my_robots = state.robots_by_player[whoami] + for rx, ry, energy in my_robots: + if state[rx, ry].city == '+' and state[rx, ry].allegiance != whoami: + orders.append('P') + continue + potential_orders = [] + if state[rx, ry].allegiance != whoami: + potential_orders.append('P') + if state[rx + 1, ry].city != 'X': + potential_orders.append('R') + if state[rx - 1, ry].city != 'X': + potential_orders.append('L') + if state[rx, ry + 1].city != 'X': + potential_orders.append('D') + if state[rx, ry - 1].city != 'X': + potential_orders.append('U') + + if potential_orders: + # Make a random move for each robot + orders.append(random.choice(potential_orders)) + else: + # There are no valid moves, so do nothing for this robot + orders.append('-') + + return orders -- cgit v1.2.3