Skip to content

This is a test project for to try Reinforcement Learning (Q-Learning) and machine learning on PHP

License

Notifications You must be signed in to change notification settings

jarenal/tictactoe-reinforcement-learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to TicTacToe Reinforcement Learning on PHP

This is a test project for to try Reinforcement Learning (Q-Learning) and machine learning on PHP

Setup

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.

Option 1: Using built-in PHP Web Server

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:

http://localhost:8080

Option 2: Using Apache

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:

http://www.example.com

Training

The game use a Machine Learn algorithm called Q-Learning

For to train the AI you will have to do the next steps:

  1. Assign full permissions to database folder located inside your project folder.
  2. Enter into database folder.
  3. 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

Tests

You can execute the tests running the next command:

    $ cd PROJECT_FOLDER
    $ ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests

Authors

  • Jose Antonio - Initial work

Donations

If you found this useful. Please, consider support with a small donation:

  • BTC - 1PPn4qvCQ1gRGFsFnpkufQAZHhJRoGo2g5
  • BCH - qr66rzdwlcpefqemkywmfze9pf80kwue0v2gsfxr9m
  • ETH - 0x5022cf2945604CDE2887068EE46608ed6B57cED8

License

This project is licensed under the ISC License - see the LICENSE file for details

About

This is a test project for to try Reinforcement Learning (Q-Learning) and machine learning on PHP

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published