b5d696bf3083d83a0a17099540d198923d6416cd
🕹️ Connect 4 AI: Grandmaster Edition (v2.5)
A high-performance Connect 4 implementation for the ESP32-C3 (RISC-V). This version features a "Killer Instinct" AI, human-like animations, and a real-time interrupt system.
🛠 Hardware Configuration
🔌 Pin Mapping (Lolin C3 Mini)
| Component | ESP32-C3 Pin | Function |
|---|---|---|
| NeoPixel Matrix | GPIO 4 |
Data Input (DIN) |
| Rotary Encoder A | GPIO 0 |
Directional CLK |
| Rotary Encoder B | GPIO 1 |
Directional DT |
| Encoder Button | GPIO 2 |
Selection/Abort (SW) |
📐 Physical Layout
- Game Board: 7 Columns x 6 Rows.
- Top Row (Row 0): Interaction row (Selection & AI Thinking pulse).
- UI Border: Row 1 and Column 7 (Blue frame, toggleable via
SHOW_BORDER). - Coordinate Formula:
Index = (y \times 8) + x
🧠 Advanced AI Features
1. Offense-Priority Strategy
The AI follows a strict 3-phase move evaluation:
- Lethal: If the AI can connect four this turn, it takes the win immediately.
- Defensive: If the human player has a lethal move, the AI blocks it.
- Strategic: If no immediate wins exist, it runs a deep Minimax search.
2. High-Priority Interrupts
The AI's single-core RISC-V processor is kept responsive via an "Abort Flag." Pressing the button or turning the encoder during an AI calculation (Demo or Playing) immediately kills the recursion and returns the user to the Menu.
3. Evolution Mode
AI difficulty scales dynamically: DynamicPly = BasePly + \lfloor \frac{DiscsOnBoard}{7} \rfloor.
🛠 Installation & Build
- Environment: VS Code with PlatformIO.
- Dependencies:
FastLED,Encoder,Preferences. - Build Flags: -
-D SHOW_BORDER=1(Enables blue frame)-D SHOW_BORDER=0(Full-screen board mode)
Description
Languages
Python
54%
JavaScript
25.1%
C++
20.2%
HTML
0.7%