Skip to main content

A Python library to create and use machine learning TrackMania AIs.

Project description

TMLearner

tmlearner is a library that allows for training and using custom TrackMania AIs with machine learning. It works with any version of TrackMania - or any game that uses only arrow keys, this library trains a TrackMania bot to play just like your style of driving, by feeding the neural network screenshots to predict the next keys to press Note: tmlearner must be run with administrator privileges for the keyboard module to work when tabbed out, which is essential for use.

Features

Feature Support
Screenshot input ✅Supported
Other data (yaw, speed) input 🟥Not supported
Digital output ✅Supported
Analog output 🟨Coming soon

Documentation

The tmlearner library has two main files, the main TMLearner class, and two functions named wasd_key_test and arrow_key_test for testing input functionality.

Input Testing

Execute the wasd_key_test and arrow_key_test functions depending on the keys that you prefer to test as input. Then, press some keys to test. Example usage of the test functions:

>>> from tmlearner import wasd_key_test, arrow_key_test
>>> wasd_key_test()
Press some WASD keys.
*User presses keys*
W pressed
A pressed
D pressed
W pressed
S pressed
S pressed
KeyboardInterrupt
>>> arrow_key_test()
*User pressed keys*
up pressed
left pressed
down pressed
up pressed
right pressed
down pressed
down pressed

TMLearner Class

Initialization

The TMLearner class is the main class used to create datasets, train models, and test models. Example usage of the TMLearner class:

>>> from tmlearner import TMLearner
>>> bot = TMLearner()

The various parameters are shown here:

Parameter Description Type
name The name of the bot. The files will be named with this name. str
keys Should be "WASD" or "ARROW". Which set of keys you will be pressing as input. str
data_capture_interval The delay in seconds to capture frames when creating a dataset. int, float
exec_capture_interval The delay in seconds to capture frames when using the model. int, float
save_frequency The frequency to save the database when creating a database. Set to None for no auto-saving. int, None
img_size The size images are scaled to for training tuple
nn_arch The architecture of the neural network. tuple
nn_random_state The random state of the neural network. Use for reproducibility. int
nn_test_percentage The percentage of the dataset to hold for testing. float
verbose Whether to allow printing debug data. Some critical information will be printed regardless. bool

Deleting the Files

TMLearner.delete_database method will delete the database file, the image folder, and the model file. Coming soon: Delete database but keep model. Example usage:

>>> bot.delete_database()
Deleted all of tmlearner_bot data.

Dataset Creation

TMLearner.create_database creates/adds to the existing database. You will be prompted to press [ENTER], and a 5 second countdown will commence. When it ends, data (screenshots + keys) will start being recorded. Hold the stop key, 'z', for about twice your data_capture_interval to stop and save. Example usage:

>>> bot.create_database()
Press [ENTER] to begin recording.
You will have 5 seconds to switch to TM.
Hold 'x' for about 0.5 seconds to stop.
DO NOT keyboard interrupt.

*user presses [ENTER]*
5... 4... 3... 2... 1...
GO!

Capture 1 complete. State: (False, False, True, False)
Capture 2 complete. State: (False, True, True, False)
Capture 3 complete. State: (False, True , True, False)
Capture 4 complete. State: (True, False, False, False)
*user presses 'z'*
Stopping and saving.

The dataset will be created and saved.

Model Training

TMLearner.train_model function will train the neural network with the specified settings and save in a local file. Example usage:

>>> bot.train_model()
*various debug message showing progress (if verbose), and final print showing accuracy*

Using the Model

TMLearner.run_model will actually use the model, giving the user 5 seconds to switch to the TrackMania window, before taking screenshots, running them through the model, and executing the output. The TMLearner.exec_capture_interval parameter will control the frequency that images are taken and processed. Example usage:

>>> bot.run_model()
Press [ENTER] to begin. You will have 5 seconds to switch to TM.

*user presses [ENTER]*
5... 4... 3... 2... 1...
GO! (Ctrl+C to stop)

Prediction: (False, False, True, False)
Prediction: (False True, True, False)
Prediction: (True, False, False, True)
*user pressed Ctrl+C*
Stopping. Releasing all keys.
Done

Version History

1.1.0

  • First release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tmlearning-1.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tmlearning-1.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file tmlearning-1.1.0.tar.gz.

File metadata

  • Download URL: tmlearning-1.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for tmlearning-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3d9789a2160cba27f8892c2a8c3dda6f4ca942bfc635cf88d59f2ae9b30b3617
MD5 f2e25f5f824eb99d9334d2f5fa969681
BLAKE2b-256 75879e9f81e9bfa5a92f3833698b7ca536403eb3889659f1ed043d4d22ee1f9d

See more details on using hashes here.

File details

Details for the file tmlearning-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tmlearning-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for tmlearning-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15677580a505b46982935bfed94fbec2133b878fd32cfa9045cdfc4e5d80af9c
MD5 c3940a908c275b98bd184de8888bb0f7
BLAKE2b-256 d9cc08e11fb8bf811fc7b9c1f0c32ceb89fe06d8d9b3c6b3ec027ae40eafcf78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page