blob: 0a84b96bc845acbca4966c47f1f4250669fa13bf (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
|