Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tic tac toe game in python #993

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lavya30
Copy link

@lavya30 lavya30 commented Oct 17, 2024

This project is a Python implementation of the classic Tic-Tac-Toe game. The game offers two modes for users to choose from: single-player mode, where the player competes against the computer, and multiplayer mode, where two players can compete against each other. The game is played on a 3x3 grid, where players take turns to mark positions on the board with either "X" or "O". The objective is to align three of your marks horizontally, vertically, or diagonally.

Key features of this project include:

User-friendly interface: Players input their moves by selecting positions on the grid, which is represented numerically from 1 to 9. Single-player mode: The player competes against the computer, which uses a minimax algorithm to make optimal moves. The player can choose whether to play first or second. Multiplayer mode: Two human players take alternate turns, with one playing as "X" and the other as "O". Game status detection: The game continually checks for a win or draw after each move using a function that evaluates all possible winning combinations. Error handling: The program ensures valid moves, preventing players from overwriting existing marks, and exits if an invalid move is made. Functions Overview:

user1turn(): Handles Player 1's turn, allowing them to place "X" on the board and checking for valid moves.
user2turn(): Handles Player 2's turn in multiplayer mode, allowing them to place "O" and check for valid moves.
displayboard(): Displays the current state of the game board after each move.
analyzeboard(): Analyzes the game board to check if a player has won or if the game is a draw.
minmax(): Implements the minimax algorithm to evaluate possible moves for the computer in single-player mode, ensuring the best possible play.
computerturn(): Executes the computer's move in single-player mode by leveraging the minimax function.
main(): The main function that coordinates the game logic, allowing users to select between single and multiplayer modes and manages game flow.

This project is a Python implementation of the classic Tic-Tac-Toe game. The game offers two modes for users to choose from: single-player mode, where the player competes against the computer, and multiplayer mode, where two players can compete against each other. The game is played on a 3x3 grid, where players take turns to mark positions on the board with either "X" or "O". The objective is to align three of your marks horizontally, vertically, or diagonally.

Key features of this project include:

User-friendly interface: Players input their moves by selecting positions on the grid, which is represented numerically from 1 to 9.
Single-player mode: The player competes against the computer, which uses a minimax algorithm to make optimal moves. The player can choose whether to play first or second.
Multiplayer mode: Two human players take alternate turns, with one playing as "X" and the other as "O".
Game status detection: The game continually checks for a win or draw after each move using a function that evaluates all possible winning combinations.
Error handling: The program ensures valid moves, preventing players from overwriting existing marks, and exits if an invalid move is made.
Functions Overview:

user1turn(): Handles Player 1's turn, allowing them to place "X" on the board and checking for valid moves.
user2turn(): Handles Player 2's turn in multiplayer mode, allowing them to place "O" and check for valid moves.
displayboard(): Displays the current state of the game board after each move.
analyzeboard(): Analyzes the game board to check if a player has won or if the game is a draw.
minmax(): Implements the minimax algorithm to evaluate possible moves for the computer in single-player mode, ensuring the best possible play.
computerturn(): Executes the computer's move in single-player mode by leveraging the minimax function.
main(): The main function that coordinates the game logic, allowing users to select between single and multiplayer modes and manages game flow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant