This project is a Python implementation of Tic-Tac-Toe and its various gameplay variants. It was developed as part of a group project, starting from an incomplete program provided by instructors. The goal was to create a functional Tic-Tac-Toe game playable in both terminal and graphical interfaces using the pygame
module. This is a two-player game, and there is no AI opponent available.
- Standard Tic-Tac-Toe: Classic three-in-a-row win condition.
- Counter Mode: The winner is determined by the number of three-in-a-row alignments.
- Moveable Mode: After placing all pieces, players can move their stones.
- Middle Variant: The game starts with the first move in the center.
- Adjacent Variant: Pieces can only be moved to adjacent empty spaces.
- Misery Mode: The player who aligns three stones first loses.
- Clone the repository:
git clone <repository_url> cd tic-tac-toe-variants
- Install dependencies:
pip install pygame
Run the game in either terminal or GUI mode:
python main_txt.py # Terminal version
python main_gui.py # Pygame version
At the start, players can select which variant to play and the board size using interactive input prompts.
- In
main_txt.py
: Players place pieces by typingx y
, wherex
andy
are within the range[0, board_size]
.x
represents the position on the x-axis, andy
represents the position on the y-axis. - In
main_gui.py
: Players place pieces by clicking directly on the corresponding position on the board.
main_txt.py
: Terminal-based version of the game.main_gui.py
: Graphical version using Pygame.constants.py
: Contains game constants and settings.- Variant scripts:
default.py
: Standard Tic-Tac-Toecounter.py
: Counts alignments to determine the winnermoveable.py
: Allows stone movementmisery.py
: Reverse win condition
- Initial research involved studying Tic-Tac-Toe implementations online.
- A basic terminal version was created first.
- The graphical version was implemented using
pygame
. - Variants were added incrementally, refining game logic.
- Debugging was done using print statements to track errors and logic flaws.
- Improve GUI with animations and better graphics.
- Implement AI for single-player mode.
- Add an online multiplayer mode.
- Zhihao Chen & Pengcheng Chen