A terminal-based Connect Four game written in Python, featuring emoji game pieces and a built-in AI opponent that can spot winning moves and block yours.
- About
- Features
- Demo
- How to Play
- Installation
- Usage
- Game Logic Overview
- Project Structure
- Known Limitations
- Roadmap
- Author
- License
Puissance4 (French for Connect Four) is a classic two-player strategy game reimplemented in pure Python, playable directly in your terminal. The player competes against a computer opponent on a traditional 7-column x 6-row grid, using emoji pieces (🏐️ / 😁️) instead of plain characters for a more playful experience.
The goal is simple: align four pieces in a row — horizontally, vertically, or diagonally — before the computer does.
- 🕹️ Fully playable in the terminal, no external dependencies
- 🤖 Computer opponent with basic decision-making:
- Checks if it can win immediately
- Blocks the player's winning move if it can't win itself
- Otherwise picks a strategic column based on row priority
- 🧩 Full win detection: horizontal, vertical, and both diagonal directions
- 😁️ Emoji-based game pieces for a fun visual touch
- 🔁 Replay option at the end of each game
___________a_______________b_________________c_______________d________________e________________f________________g_____________
| } } } } } } }
| 😁️ } 😁️ } 🏐️ } 🏐️ } 😁️ } } 😁️ }
| } } } } } } }
(Example of a mid-game board state — columns are selected by letter, pieces drop to the lowest available row.)
- Launch the game — you'll be asked to enter a pseudo (your name).
- Choose your piece color:
blanc(white 🏐️) orjaune(yellow 😁️). - On your turn, type the letter of the column (
atog) where you want to drop your piece. - The piece automatically falls to the lowest empty slot in that column.
- The computer plays its turn right after you.
- First to align 4 pieces in a row (any direction) wins!
- At the end of a round, choose to play again or quit.
No external libraries required — only the Python standard library.
git clone https://github.com/DonaFidele/Puissance4.git
cd Puissance4Requirements:
- Python 3.x
Run the game from your terminal:
python3 puissance4.py💡 For best results, use a terminal that supports emoji rendering (most modern terminals on macOS/Linux do; on Windows, use Windows Terminal rather than the classic
cmd.exe).
- The board is represented internally as a 42-cell grid (7 columns × 6 rows), mapped with numbers
01–42. - Columns are addressed by letters
a–g; the game calculates the lowest available cell in the chosen column using regex-based cell tracking. - Win detection (
end_game) checks all four alignment directions by splitting the grid into 6 rows and comparing adjacent cells. - The AI (
ordi_game) follows a simple priority strategy:- Win if a winning move is available.
- Block the opponent's winning move.
- Fallback: pick a random available column, prioritizing lower rows first.
Puissance4/
│
└── puissance4.py # Main game file — contains the Puissance_4 class and game loop
- No input validation for full columns — selecting a completely filled column may cause unexpected behavior.
clean()usesos.system("clear"), which is Unix/macOS-specific (won't work as-is on Windowscmd.exe).- Display formatting depends on emoji rendering width, which can vary slightly across terminals.
- Handle full-column selection gracefully
- Cross-platform terminal clearing (Windows support)
- Optional two-player (human vs human) mode
- Smarter AI (minimax algorithm)
DonaFidele GitHub Profile
Free to fork and contribute.
Made with 🏐️😁️ by Dona😎