BaghChal Project with MCTS

Welcome to BaghChal project. Project Members: Hem Regmi https://github.com/hregmi77 , Rojina Panta

Data Generation

The data here can be generated by running CollectectObservations.py. The data is generated using minmax algorithm and random player.

The directory structure after CollectObservations.py will be

        ---------->BaghChaalProject
                 ------------>BaghAsMinMax_GoatAsMinMax
                 ------------>BaghAsMinMax_GoatAsRandom
                 ------------>GoatAsMinMax_BaghAsRandom
 

We also have self created humanplayerdata. The directory structure fo human player data will be

      ------------>BaghChaalProject
              -------------->humanplayerdata

It might take a while to generate this data so we have also uploaded the data in dropbox which can be inserted inside project folder into the structure mentioned above with code for BaghChal Project.

The link to dropbox is

[Link to Dropbox] (https://www.dropbox.com/sh/sxu6msufgph6so7/AAAocWfZe1hp0qzN-y7kiSKpa?dl=0&fbclid=IwAR263VWbwS0SkCGCFcHiVcZcxxFRq7l7oCn1Xk-jMahMDo2b9KEgO0cpeC4)

This data is used for pretraining neural network.

Training Network

There are two phases in which the network is trained. Firstly the network is trained with data generated above. And this trained network is again trained with MCTS algorithm during self play.

For this we run code main_baghchall_all.py

The models that are trained with collected data and self play data are saved in models directory ```

    ---------->BaghChaalProject
             ----->models
                ----->model
                    ----->pretrain_model # for model trained with collected data
                    ----->self_play_model # for model trained with mcts self play with or without pretrained model
                    
      ```

The dropbox link metioned earlier also have model file.

The data trained with selfplay model is saved in folder selfplay_data.

Evaluation Network

For the evaluation of previously trained network we use evaluate_baghchal.py which saves the result of player currently playing (Tiger or Goat), which player won the game and the algorith with which trained mcts is playing.

We also can play game of baghchal using play_baghchal_game.py.

Here trained MCTS plays with minmax, untrained mcts or random player. And the trained MCTS suggests plays accordingly.

Steps to run the code

Firstly create environmet using eirher requirement.txt or environment.yml file.

We can run the code by running main.py

Where we can choose between options

        [
            "Generate Data",
            "Train both pretrain model and self play model",
            "Load pretrained model and train self play with pretrained model",
            "Generate Data, train pretrain model",
            "Train with self play model only",
            "Play Baghchal",
            "Evaluate model",
            "Exit",
        ]
    ```
    
    The first option is used to generate data only.
    The second option is used to train both pretrain model with collected data and self play model.
    The third option is used to load previously trained pretrain model and self play model.
    The fourth option is used to generate data and train pretrain and self play model. This is if we want to start all the baghchal data collection and training process from scratch.
    The fifth option is used to train self play mcts model without pretrain model and collected data.
    The sixth option is used to play baghchal using information from mcts network.
    The seventh option is used to evaluate result of previously trained model.
    The eigth option is used to get out of the main loop.
    
    ```

Here, since we have trained collected and trained data we can

run python main.py and select option 5.

But before that we have to download all the required data and place it in BaghChal project folder which has the main code and is provided in the dropbox link above.