aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/assets
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-02-21 21:00:05 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-02-21 21:00:05 +0100
commit060b585da1d6beb7dc214d1eb70bcd73ac41ed86 (patch)
tree2800fdad03797148afea5d05985c771343fbc29b /web/pw-server/src/assets
parent9c90e79575afb3ab2574f1d7e0fc79d7fae90458 (diff)
downloadplanetwars.dev-060b585da1d6beb7dc214d1eb70bcd73ac41ed86.tar.xz
planetwars.dev-060b585da1d6beb7dc214d1eb70bcd73ac41ed86.zip
add default code to get started
Diffstat (limited to 'web/pw-server/src/assets')
-rw-r--r--web/pw-server/src/assets/bot_template.txt30
1 files changed, 30 insertions, 0 deletions
diff --git a/web/pw-server/src/assets/bot_template.txt b/web/pw-server/src/assets/bot_template.txt
new file mode 100644
index 0000000..82fa497
--- /dev/null
+++ b/web/pw-server/src/assets/bot_template.txt
@@ -0,0 +1,30 @@
+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 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:
+ # no valid moves can be made
+ move(None)
+ else:
+ # send some ships!
+ move({
+ 'origin': my_planets[0]['name'],
+ 'destination': other_planets[0]['name'],
+ 'ship_count': 1
+ })