We understand the importance of a visually appealing and intuitive user interface. The project will be updated to include an improved graphical user interface (GUI) for a more engaging and enjoyable gaming experience.
To simplify the installation process, we will be providing Debian (.deb) packages for Linux systems and executable (.exe) files for Windows. This will make it easier for users to install and run the Tic Tac Toe game without worrying about dependencies or setup complexities.
Stay tuned for these exciting updates, and enjoy an even better Tic Tac Toe gaming experience! If you have any suggestions or feedback, feel free to let us know.
A Python Tic Tac Toe game played by two-players on a 3x3 grid. (Due to this project being updated, this documentation will be updated as well).
Tic Tac Toe is a classic two-player game played on a 3x3 grid. The objective is to get three marks ('X' or 'O') in a row (horizontally, vertically, or diagonally) or end the game in a draw. This project showcases various programming concepts, including lambda expressions, classes, object-oriented programming, exception handling, conditional statements, loops, and the use of the tabulate
library.
To run this game, you need the tabulate
module, which you can install using pip or conda:
pip install tabulate
# OR
conda install tabulate
To play the game, execute the Main()
constructor from the main.py
file:
from main import Main
Main()
The game features a menu with the following options:
Select option 1 to start a game. Enter the number of matches you want to play and begin playing. After each match, the result will be displayed on the screen.
Choose option 2 to view the score card. The score card displays the number of matches played, matches won by player X, matches won by player O, and the number of draws.
Select option 3 to exit the game.
The Game
class represents the Tic Tac Toe game. It provides the following methods:
__init__
: Initializes the game board and win conditions for player X and player O.play_game
: Draws the board and takes input from the user.draw_board
: Displays the current board state using thetabulate
module.play_move
: Places the current player's mark on the board, updates the game board, and draws the updated board.input
: Takes and validates user input, checks for valid range and unoccupied cells, and handles moves.draw_condition
: Checks for a draw in the game.wins
: Determines the winner (1 for X, 0 for O, -1 for no winner yet).gameNotFinished
: Checks if the game is still in progress.is_unplayable
: Identifies impossible game states, e.g., both X and O winning.diagonalMat
: Returns the two diagonals of the board.colMat
: Returns the columns of the board.countX
: Counts the number of 'X' marks.countO
: Counts the number of 'O' marks.has_empty_cells
: Checks for empty cells on the board.
The Main
class represents the game's main menu and handles game execution. It provides the following methods:
__init__
: Constructor for theMain
class, displaying the menu and processing user choices.play
: Starts and manages Tic Tac Toe games based on the specified count.score_card
: Displays game statistics, including total games played, games won, games lost, and draws, in a tabulated format.greet_user
: Shows a welcome message and the game menu.add_score
: Updates the global game statistics.
This documentation has provided insights into the Tic Tac Toe project, covering its purpose, installation, usage, and internal workings. Whether you're a player or a developer interested in the code, enjoy playing Tic Tac Toe! If you have any questions or need further assistance, feel free to ask.