The Simple Demo example is a scenario that demonstrates a scripted agent interacting with the BLADE Gymnasium environment. In the scenario, the scripted agent directs an aircraft to strike an enemy aircraft, infiltrate two enemy SAMs, and finally return to base. The demo is available at demo.py. Below we give a brief explanation of the demo code. Make sure you follow the installation steps before proceeding.
The code snippet below instantiates a BLADE Gymnasium environment. Note that we must first create a Game object instantiated with a scenario JSON file and pass it into the environment. Scenario JSON files can be generated using the panopticon-ai web application.
game = Game(current_scenario=Scenario())
with open(f"{demo_folder}/simple_demo.json", "r") as scenario_file:
game.load_scenario(scenario_file.read())
env = gymnasium.make("blade/BLADE-v0", game=game)
observation, info = env.reset()
The code snippet below defines a simple scripted agent that takes certain actions at specific timestep. At timestep 0, the agent launches a blue aircraft from Suelf AB. At timestep 1, the agent then directs the aircraft to transit to coordinates (10.9, -22.7). When the aircraft is halfway through its transit, the agent directs the aircraft to strike the red enemy aircraft with callsign "Flanker #2097." When the aircraft gets near the first transit waypoint, the agent directs the aircraft to transit to the next waypoint at coordinates (15.75, -8.97). The aircraft must fly through a tight corridor between two SAMs. When the aircraft is close enough to the enemy airbase, the agent will direct the aircraft to return to base.
The demo outputs observations to JSON files at specific timesteps for visualization. The following code snippet defines the main environment/simulation loop.
steps = 35000
for step in range(steps):
action = simple_scripted_agent(observation)
observation, reward, terminated, truncated, info = env.step(action = action)
if step == 10000: # should see weapon launch here
env.unwrapped.export_scenario(f"{demo_folder}/simple_demo_t{step}.json")
elif step == 20000: # red aircraft should be destroyed
env.unwrapped.export_scenario(f"{demo_folder}/simple_demo_t{step}.json")
elif step == 30000: # blue aircraft should be near enemy airbase if it did not get destroyed
env.unwrapped.export_scenario(f"{demo_folder}/simple_demo_t{step}.json")
env.unwrapped.export_scenario(f"{demo_folder}/simple_demo_t{steps}.json") # aircraft rtb