Skip to content

How to use

Théophile JR edited this page Dec 15, 2024 · 6 revisions

My_Torch Usage Guide

Overview

My_Torch is a neural network toolkit designed for chess state analysis. It consists of two main components:

  • Network Generator (my_torch_generator)
  • Network Analyzer (my_torch_analyzer)

Installation

  1. Clone the repository:
git clone git@github.com:FppEpitech/MyTorch.git
cd my_torch
  1. Build the project:
make

This will generate two executables:

  • my_torch_generator
  • my_torch_analyzer

Network Generator

Usage

./my_torch_generator config_file_1 nb_1 [config_file_2 nb_2...]

Parameters

  • config_file_X: Configuration file path
  • nb_X: Number of networks to generate

Example

./my_torch_generator basic_network.conf 3

This generates:

  • basic_network_1.nn
  • basic_network_2.nn
  • basic_network_3.nn

Network Analyzer

Usage

./my_torch_analyzer [--predict | --train [--save SAVEFILE]] LOADFILE FILE

Parameters

  • --predict: Use network to predict chess states
  • --train: Train network using input data
  • --save SAVEFILE: Save trained network (optional)
  • LOADFILE: Neural network file (.nn)
  • FILE: Input data file

Examples

  1. Predict chess states:
./my_torch_analyzer --predict network_1.nn chess_positions.txt
  1. Train network:
./my_torch_analyzer --train network_1.nn training_data.txt
  1. Train and save network:
./my_torch_analyzer --train --save new_network.nn network_1.nn training_data.txt

Input File Format

Training Data

Each line contains:

FEN_string expected_output

Example:

rnbqkbnr/pppp2pp/8/4pp1Q/3P4/4P3/PPP2PPP/RNB1KBNR b KQkq - 1 3 Checkmate

Prediction Data

Each line contains a FEN string:

rnbqkbnr/pppp2pp/8/4pp1Q/3P4/4P3/PPP2PPP/RNB1KBNR b KQkq - 1 3

Output Format

Training Mode

Displays training progress and final accuracy:

Iteration X: Prediction - Target
...
result: XX.XX%

Prediction Mode

Outputs chess state classification for each input:

  • Checkmate Black
  • Checkmate White
  • Stalemate
  • Nothing
  • Check White
  • Check Black

Error Handling

The program exits with code 84 if:

  • Invalid command line arguments
  • File not found
  • Invalid file format
  • Neural network errors

FEN (Forsyth-Edwards Notation)

FEN is a standard notation used to describe the state of a chess game. It encodes the position of pieces, the player to move, castling rights, en passant possibilities, half-move clock, and full-move number.

For example, the FEN: rnbqkbnr/pppp2pp/8/4pp1Q/3P4/4P3/PPP2PPP/RNB1KBNR b KQkq - 1 3 Checkmate

Explanation (each rows are separated by a /):

  • rnbqkbnr: Black's pieces (from left to right) on the 8th rank.
  • pppp2pp: Black's pawns on the 7th rank.
  • 8: Empty 6th rank.
  • 4pp1Q: Black pawns and a White Queen on the 5th rank.
  • 3P4: White pawn on the 4th rank.
  • 4P3: White pawn on the 3rd rank.
  • PPP2PPP: White pawns on the 2nd rank.
  • RNB1KBNR: White's pieces (from left to right) on the 1st rank

You can eventually put in the end of the line the outcome, in this case Checkmate. You can put :

  • Checkmate White
  • Checkmate Black
  • Check Black
  • Check White
  • Nothing
  • Stalemate