Coder Social home page Coder Social logo

tic-tac-toe's Introduction

Python Tic-Tac-Toe with Minimax Algorithm

This Python script implements a simple Tic-Tac-Toe game where a human player can play against an AI that uses the minimax algorithm. The game is played on a 3x3 board.

Features

  • Human vs AI Gameplay: Play against a computer AI that evaluates moves using the minimax algorithm.
  • Command Line Interface: Simple text-based interface to play the game in the command line.
  • Input Validation: Ensures that only valid integers are accepted as input.

Requirements

This script requires Python 3.x. No additional libraries are necessary.

Code Structure

  • read_int(prompt): Function to read and validate integer inputs.
  • check_winner(board): Function to check the current state of the board for a winner or a draw.
  • minimax(board, depth, is_maximizing, player): The minimax function to calculate the best move for the AI.
  • TicTacToe Class:
    • Methods to manage game state, validate moves, make moves, and display the board.

Game Flow

  1. The game is initiated and the board is displayed.
  2. Player 1 (human) is prompted to enter a move.
  3. Player 2 (AI) calculates and makes the next move.
  4. Steps 2 and 3 repeat until the game ends with a win or a draw, at which point the final board state is displayed along with the result.

Contributing

Feel free to fork this repository, make changes, and submit pull requests if you have suggestions or improvements. This is a simple educational project and contributions are welcome!

tic-tac-toe's People

Contributors

elenalaura366 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.