diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-28 14:57:41 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-28 14:57:41 +0100 |
commit | dacc05a41b77bf2e86e27ac354db9b047c661a7d (patch) | |
tree | 3d71fa60ff3449f73ec8bb6066ae82733eb46ee4 /planetwars-cli/assets/simplebot.py | |
parent | 5ca8dd4c842ee681ce81a6a7bbd5005cd5b98d3c (diff) | |
download | planetwars.dev-dacc05a41b77bf2e86e27ac354db9b047c661a7d.tar.xz planetwars.dev-dacc05a41b77bf2e86e27ac354db9b047c661a7d.zip |
refactor workspace code
Diffstat (limited to 'planetwars-cli/assets/simplebot.py')
-rw-r--r-- | planetwars-cli/assets/simplebot.py | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/planetwars-cli/assets/simplebot.py b/planetwars-cli/assets/simplebot.py deleted file mode 100644 index b2a6b8f..0000000 --- a/planetwars-cli/assets/simplebot.py +++ /dev/null @@ -1,33 +0,0 @@ -import sys, json - -def move(command): - """ print a command record to stdout """ - moves = [] - if command is not None: - moves.append(command) - - print(json.dumps({ 'moves': moves })) - # flush the buffer, so that the gameserver can receive the json-encoded line. - sys.stdout.flush() - - -for line in sys.stdin: - state = json.loads(line) - # you are always player 1. - my_planets = [p for p in state['planets'] if p['owner'] == 1] - other_planets = [p for p in state['planets'] if p['owner'] != 1] - - if not my_planets or not other_planets: - # we don't own any planets, so we can't make any moves. - move(None) - else: - # find my planet that has the most ships - planet = max(my_planets, key=lambda p: p['ship_count']) - # find enemy planet that has the least ships - destination = min(other_planets, key=lambda p: p['ship_count']) - # attack! - move({ - 'origin': planet['name'], - 'destination': destination['name'], - 'ship_count': planet['ship_count'] - 1 - }) |