mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 13:23:56 -07:00
Implement a simple HTTP server to start games, receive the gamestate and pass commands to the simulation. This is mainly intended for training reinforcement learning agents in 0 AD. As such, a python client and a small example are included. This option can be enabled using the -rl-interface flag. Patch by: irishninja Reviewed By: wraitii, Itms Fixes #5548 Differential Revision: https://code.wildfiregames.com/D2199 This was SVN commit r23917.
69 lines
1.6 KiB
Python
69 lines
1.6 KiB
Python
def construct(units, template, x, z, angle=0, autorepair=True, autocontinue=True, queued=False):
|
|
unit_ids = [ unit.id() for unit in units ]
|
|
return {
|
|
'type': 'construct',
|
|
'entities': unit_ids,
|
|
'template': template,
|
|
'x': x,
|
|
'z': z,
|
|
'angle': angle,
|
|
'autorepair': autorepair,
|
|
'autocontinue': autocontinue,
|
|
'queued': queued,
|
|
}
|
|
|
|
def gather(units, target, queued=False):
|
|
unit_ids = [ unit.id() for unit in units ]
|
|
return {
|
|
'type': 'gather',
|
|
'entities': unit_ids,
|
|
'target': target.id(),
|
|
'queued': queued,
|
|
}
|
|
|
|
def train(entities, unit_type, count=1):
|
|
entity_ids = [ unit.id() for unit in entities ]
|
|
return {
|
|
'type': 'train',
|
|
'entities': entity_ids,
|
|
'template': unit_type,
|
|
'count': count,
|
|
}
|
|
|
|
def debug_print(message):
|
|
return {
|
|
'type': 'debug-print',
|
|
'message': message
|
|
}
|
|
|
|
def chat(message):
|
|
return {
|
|
'type': 'aichat',
|
|
'message': message
|
|
}
|
|
|
|
def reveal_map():
|
|
return {
|
|
'type': 'reveal-map',
|
|
'enable': True
|
|
}
|
|
|
|
def walk(units, x, z, queued=False):
|
|
ids = [ unit.id() for unit in units ]
|
|
return {
|
|
'type': 'walk',
|
|
'entities': ids,
|
|
'x': x,
|
|
'z': z,
|
|
'queued': queued
|
|
}
|
|
|
|
def attack(units, target, queued=False, allow_capture=True):
|
|
unit_ids = [ unit.id() for unit in units ]
|
|
return {
|
|
'type': 'attack',
|
|
'entities': unit_ids,
|
|
'target': target.id(),
|
|
'allowCapture': allow_capture,
|
|
'queued': queued
|
|
}
|