diff options
author | Carlo Zancanaro <carlo@zancanaro.id.au> | 2022-09-25 00:10:13 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@zancanaro.id.au> | 2022-09-25 00:38:04 +1000 |
commit | 7daa5284f9eddf6d4b4e7838919e80ce25324bb0 (patch) | |
tree | ac92d9aa97621b4c314441a4cb7cdcab60b4f85e /manhattan.py | |
parent | e031af6e5e8324fe4cda66d9597904040b17ca80 (diff) |
Diffstat (limited to 'manhattan.py')
-rw-r--r-- | manhattan.py | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/manhattan.py b/manhattan.py deleted file mode 100644 index f64b1e2..0000000 --- a/manhattan.py +++ /dev/null @@ -1,61 +0,0 @@ -import random - -def distance(x1, y1, x2, y2): - ''' - >>> distance(0, 0, 3, 0) - 3 - >>> distance(1, 1, 3, 3) - 4 - ''' - return abs(x1 - x2) + abs(y1 - y2) - -def direction_to(rx, ry, fx, fy): - ''' - >>> direction_to(0, 0, 3, 0) - 'R' - >>> direction_to(0, 0, 0, 3) - 'D' - >>> direction_to(6, 0, 3, 0) - 'L' - >>> direction_to(0, 6, 0, 3) - 'U' - ''' - moves = [] - if fx < rx: - moves.append('L') - elif fx > rx: - moves.append('R') - if fy < ry: - moves.append('U') - elif fy > ry: - moves.append('D') - return random.choice(moves) - -def closest_factory(whoami, state, rx, ry): - closest_factory = None - closest_distance = 9999999 - - for fx, fy in state.factories: - if state.allegiances.get((fx, fy)) != whoami: - d = distance(rx, ry, fx, fy) - if d < closest_distance: - closest_factory = (fx, fy) - closest_distance = d - - return closest_distance, closest_factory - -def manhattan(whoami, state): - orders = [] - - for rx, ry, energy in state.robots_by_player[whoami]: - distance, factory = closest_factory(whoami, state, rx, ry) - - if factory is None or random.random() < 0.1: - orders.append(random.choice('UDLRP')) - elif distance == 0: - orders.append('P') - else: - fx, fy = factory - orders.append(direction_to(rx, ry, fx, fy)) - - return orders |