add default code to get started
This commit is contained in:
parent
9c90e79575
commit
060b585da1
2 changed files with 33 additions and 1 deletions
30
web/pw-server/src/assets/bot_template.txt
Normal file
30
web/pw-server/src/assets/bot_template.txt
Normal file
|
@ -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
|
||||||
|
})
|
|
@ -10,6 +10,8 @@
|
||||||
import ace from "ace-builds/src-noconflict/ace?client";
|
import ace from "ace-builds/src-noconflict/ace?client";
|
||||||
import * as AcePythonMode from "ace-builds/src-noconflict/mode-python?client";
|
import * as AcePythonMode from "ace-builds/src-noconflict/mode-python?client";
|
||||||
|
|
||||||
|
import defaultBotCode from "../assets/bot_template.txt?raw";
|
||||||
|
|
||||||
let matches = [];
|
let matches = [];
|
||||||
|
|
||||||
let selectedMatchId: string | undefined = undefined;
|
let selectedMatchId: string | undefined = undefined;
|
||||||
|
@ -22,7 +24,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
function init_editor() {
|
function init_editor() {
|
||||||
editSession = new ace.EditSession("");
|
editSession = new ace.EditSession(defaultBotCode);
|
||||||
editSession.setMode(new AcePythonMode.Mode());
|
editSession.setMode(new AcePythonMode.Mode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue