Race¶
To start a race create a new Race object.
You can configure your race using the RaceConfig
object, see Configuration.
You need to set the graphics settings before starting a race, see Graphics Setup.
pystk.init(pystk.GraphicsConfig.hd())
config = pystk.RaceConfig(track='lighthouse', num_kart=2)
config.players[0].controller = pystk.PlayerConfig.Controller.AI_CONTROL
race = pystk.Race(config)
race.start()
n_steps = 100
for step in range(n_steps):
race.step() # Use an optional action and set controller to pystk.PlayerConfig.Controller.PLAYER_CONTROL
# Use race.render_data[0].image
# Use race.render_data[0].depth
# Use race.render_data[0].instance
race.stop()
del race
# You may start a new race after you delete the old race object
pystk.clean()
- class pystk.Race¶
The SuperTuxKart race instance
- __init__(self: pystk.Race, config: pystk.RaceConfig)¶
- restart(self: pystk.Race) None ¶
Restart the current track. Use this function if the race config does not change, instead of creating a new SuperTuxKart object
- start(self: pystk.Race) None ¶
start the race
- step(*args, **kwargs)¶
Overloaded function.
step(self: pystk.Race, action: List[pystk.Action]) -> bool
Take a step with an action per agent
step(self: pystk.Race, action: pystk.Action) -> bool
Take a step with an action for agent 0
step(self: pystk.Race) -> bool
Take a step without changing the action
- stop(self: pystk.Race) None ¶
Stop the race
- property config pystk.RaceConfig ¶
The current race configuration
- property render_data List[pystk.RenderData] ¶
rendering data from the last step
SuperTuxKart uses several global variables and thus only allows one game instance to run per process.
To check if there is already a race running use the is_running
function.
- pystk.is_running() bool ¶
Is a race running?