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 /capturer.py | |
parent | e031af6e5e8324fe4cda66d9597904040b17ca80 (diff) |
Diffstat (limited to 'capturer.py')
-rw-r--r-- | capturer.py | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/capturer.py b/capturer.py deleted file mode 100644 index 54b0be6..0000000 --- a/capturer.py +++ /dev/null @@ -1,52 +0,0 @@ -import random - -import robots - -from robots.algorithms import distance_relaxer -from robots.constants import City -from robots.utils import add_spawns - -class CaptureSpawns(object): - def __init__(self, variance=0.1): - self.iterations = 10 - self.variance = variance - - def __call__(self, whoami, state): - my_robots = state.robots_by_player[whoami] - - # Create a distance matrix. - distances = [] - for y, row in enumerate(state.cities): - output = [] - for x, city in enumerate(row): - d = float('inf') - if city == City.FACTORY: - if state.allegiances.get((x, y)) != whoami: - d = 0 - elif city == City.GHOST: - d = None - output.append(d) - distances.append(output) - - # Find the shortest path to a target from each cell. - predecessors = distance_relaxer(distances) - - # Direct the robots to follow those paths. - results = [] - for x, y, energy in my_robots: - if random.random() < self.variance: - result = random.choice('ULDR') - elif predecessors[y][x]: - result = random.choice(predecessors[y][x]) - elif state.allegiances.get((x, y)) != whoami: - result = 'P' - else: - result = random.choice('UDLR') - results.append(result) - return results - -if __name__ == '__main__': - server = robots.Server() - server.SERVER_NAME = 'Capturer Server' - server.add_bot(CaptureSpawns, 'Capture') - server.run() |