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.

pystk2.init(pystk2.GraphicsConfig.hd())

config = pystk2.RaceConfig(track='lighthouse', num_kart=2)
config.players[0].controller = pystk2.PlayerConfig.Controller.AI_CONTROL
race = pystk2.Race(config)
race.start()

n_steps = 100
for step in range(n_steps):
    race.step() # Use an optional action and set controller to pystk2.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
pystk2.clean()
class pystk2.Race

The SuperTuxKart race instance

__init__(self: pystk2.Race, config: pystk2.RaceConfig)
get_kart_action(self: pystk2.Race, arg0: int) pystk2.Action

Get a kart control state

restart(self: pystk2.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: pystk2.Race) None

start the race

step(*args, **kwargs)

Overloaded function.

  • step(self: pystk2.Race, action: List[pystk2.Action]) -> bool

Take a step with an action per agent

  • step(self: pystk2.Race, action: pystk2.Action) -> bool

Take a step with an action for agent 0

  • step(self: pystk2.Race) -> bool

Take a step without changing the action

stop(self: pystk2.Race) None

Stop the race

property config pystk2.RaceConfig property

The current race configuration

property render_data List[pystk2.RenderData] property

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.

pystk2.is_running() bool

Is a race running?