Repository files navigation
This is a simple implementation of the Tic-Tac-Toe game in Python.
The game is played on a 3x3 grid, where two players take turns to mark a square with their respective symbol ('X' or 'O').
The player who first places three of their symbols in a horizontal, vertical, or diagonal row wins the game.
User Input Validation: Ensures that the input is a digit between 1 and 9 and that the chosen position on the board is empty.
Game Board Display: Shows the current state of the game board after every move.
Win Checking: Checks for a win condition after every move.
Player Switching: Alternates turns between Player 'X' and Player 'O'.
Copy the Code: Copy the code to a Python (.py) file, for example, tic_tac_toe.py.
Run the Script: Execute the script using Python.
python tic_tac_toe.py
Initialization: The game board is initialized as a 3x3 list with empty strings.
Display Function: display_current() prints the current state of the game board.
User Input: user_choice() prompts the user to input a number between 1 and 9.
Board Update: update_board(choice, player) updates the board with the player's move.
Win Check: check_win(player) checks if the current player has won the game.
Main Loop: main() contains the game loop, alternating between players and checking for a win after each move.
The game starts with Player 'X'.
Players take turns to enter a number between 1 and 9 to place their symbol on the board.
The game ends when one player gets three in a row or all positions are filled.
You can’t perform that action at this time.