Skip to content

This repository contains a Python implementation of a Tic-Tac-Toe game with an AI opponent powered by a neural network. The AI has been trained through self-play to make strategic moves and provides a challenging opponent for human players.

Notifications You must be signed in to change notification settings

SantosProgramming/TicTacToeAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tic-Tac-Toe AI with Neural Network

Overview

This repository contains a Python implementation of a Tic-Tac-Toe game with an AI opponent powered by a neural network. The AI has been trained through self-play to make strategic moves and provides a challenging opponent for human players.

Tic-Tac-Toe AI

Requirements

  • Python 3
  • TensorFlow (for the neural network)
  • numpy

Getting Started

  1. Clone the repository:
git clone https://github.com/SantosProgramming/TicTacToeAI
cd TicTacToeAI
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the game:
python tictactoe.py

How to Play

  • Enter your move by specifying a number from 1 to 9 corresponding to the positions on the board.
  • You can end the game at any time by entering '101'.
  • The AI will display its move, and the game board will be updated accordingly.

Neural Network Architecture

The AI utilizes a neural network with the following architecture:

model = keras.Sequential([
    keras.layers.Dense(128, activation='relu', input_shape=(BOARD_SIZE,)),
    keras.layers.Dense(64, activation='relu'),
    keras.layers.Dense(BOARD_SIZE, activation='softmax')
])

Training the Model

The model is trained through self-play using the following functions:

  • self_play(num_games, batch_size, epochs): Generates training data by simulating games between the AI and itself.
  • train_model(training_data, epochs): Trains the neural network with the generated training data.

Adjust the num_games, batch_size, and epochs parameters to customize the training process.

Playing Against the AI

Run the play_against_ai() function to engage in a game against the trained AI. The AI will make strategic moves based on its training.

Enjoy playing Tic-Tac-Toe against the AI!

About

This repository contains a Python implementation of a Tic-Tac-Toe game with an AI opponent powered by a neural network. The AI has been trained through self-play to make strategic moves and provides a challenging opponent for human players.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages