This is a test project for to try Reinforcement Learning (Q-Learning) and machine learning on PHP
Clone or download the project in a folder and then install dependencies using composer:
$ cd PROJECT_FOLDER
$ composer install
For to run the project in a browser we have two options.
For to run the app using the built-in PHP Web server:
Go to web folder inside your PROJECT FOLDER and then execute the script start.sh from your terminal.
Example:
$ cd PROJECT_FOLDER/web
$ ./start.sh
After that you can open the next url in your browser:
For Example:
For to run the app using Apache you will have to create a VirtualHost pointing to web folder of your project folder.
Example:
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/PROJECT_FOLDER/web
<Directory /var/www/PROJECT_FOLDER/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog /var/log/apache2/mytictactoe_error.log
CustomLog /var/log/apache2/mytictactoe_access.log combined
</VirtualHost>
NOTICE: Please notice that you will have to adapt paths according to your environment.
After that you can open the project from your browser using the ServerName selected.
For example:
The game use a Machine Learn algorithm called Q-Learning
For to train the AI you will have to do the next steps:
- Assign full permissions to database folder located inside your project folder.
- Enter into database folder.
- And execute the script training.php
$ cd PROJECT_FOLDER
$ chmod 777 database
$ cd database
$ php training.php
You can execute the training many times, every time that you execute it the AI should play better.
For to set how many games will train you can modify the constant TRAINING_GAMES located at config/config.php file.
When the training is finished you will see a new file located at database folder named q_table.csv. This file contains the knowledge acquired by the game during the training.
$ cd PROJECT_FOLDER/database
$ ls -la
will output:
q_table.csv // Training generated by training script
q_table.txt // A training file template
I've attached an example file named q_table.txt that you can use instead to generate a new one. Just rename the attached file from q_table.txt to q_table.csv
$ cd PROJECT_FOLDER/database
$ mv q_table.txt q_table.csv
You can execute the tests running the next command:
$ cd PROJECT_FOLDER
$ ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests
- Jose Antonio - Initial work
If you found this useful. Please, consider support with a small donation:
- BTC - 1PPn4qvCQ1gRGFsFnpkufQAZHhJRoGo2g5
- BCH - qr66rzdwlcpefqemkywmfze9pf80kwue0v2gsfxr9m
- ETH - 0x5022cf2945604CDE2887068EE46608ed6B57cED8
This project is licensed under the ISC License - see the LICENSE file for details