The project involves building of an intelligent game playing bot for the TORCS Racing environment.
Python
• Tensorflow
• Keras
In order to train an AI Bot there can be different approaches but we opted to apply behavioral cloning and see how our agent mimics the behaviour seen in the data. There were two possibilities to collect the data i.e. either we play and collect the data or we find a perfect player online from which we can extract the data. We were able to find a perfect open-source agent named Ahoora being developed in Java therefore opted for this option. Game data (offline) was generated by running Ahoora on 30 different races, comprising 3 laps each. Resulting data was dumped in a csv format which was around 10 GB.
We had data for 30 races in every track. For feeding it to neural network, 73 sensor values (features) and 5 actuator values (labels) were seperated out. Labels consisted of accleration, brake, clutch, steer angle and gear. As gear can be changed according to the speed so gear was not predicted. Training data consisted of first 29 races of every track and Validation data consisted of last race of every track. The data was normalized and then stored the means and standard deviations which will be used in making a test example.
Training data consisted of more than 11 million examples and validation data consisted of 2 million examples. Initially made a small neural network containing three hidden layers of 512, 256, 128 neurons. Model was under-fitting since the number of parameters to learn were too low. After 30 epochs, the loss became constant and the model was behaving average when tested. Tried a deeper neural network having eight layers with more neurons and this model converged nicely.
data_generation
is the folder having all the necessary files for data generation.data_generation/Ahura
is the agent from which data is extracted.- Place
data_generation/temp/temp
to/data_generation/
. - Change directory to
data_generation
usingcd data_generation
. - Run
python data_generation_server.py
. For this, we do not need to activate any environment. Default environment will be okay. It will run TORCS and then click on every first option i.e. Race, Quick Race, New Race. It will then start waiting for the client to connect ;) - Run
python data_generation_client.py
. You will see the client will connect and race will start. When the race ends, the data is generated in./data/
.
Training material is present in model/Model.ipynb
. It contains integration with sample data. Similarly one can change this notebook according to the data being generated.
- Anaconda python installed. In case anaconda is not installed, follow Anaconda Installation and install anaconda.
- Clone the repository and import the environment by running
conda env create -f torcs_env.yml
. - Activate the enviornment i.e.
conda activate torcs_env
. - Client.py is the file which tries to connect with the server. Run client.py and make sure no error comes.
- torcs_server is the folder which is required for running the server. This server was downloaded from an open source github repository. The exe file named
wtorcs.exe
is the main server file which will be used to listen from client. Runwtorcs.exe
file intorcs_server
folder and then click onRace
. - It will show multiple types of races. The one normally used for testing is
Quick race
and clicking it will show the option ofNew Race
andConfigure Race
. - First we need to configure the players therefore click on
Configure Race
. Choose the track and then clickAccept
. - There should be one server named
scr_server 1
inselected
orNot selected
tab. This is the client name which will be run therefore make sure to select thescr_server 1
. - Other cars can be added to see the performance of the agents in presence of other agents.
- Click on accept and then
Quick Race Options
will pop up. Set the options according to the requirements and click onAccept
. - Then Click on
New Race
and enjoy seeing the agent race ;-)