51 lines
1.9 KiB
Markdown
51 lines
1.9 KiB
Markdown
# 🕹️ 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:
|
|
|
|
1. **Lethal:** If the AI can connect four this turn, it takes the win immediately.
|
|
2. **Defensive:** If the human player has a lethal move, the AI blocks it.
|
|
3. **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
|
|
|
|
1. **Environment:** VS Code with PlatformIO.
|
|
2. **Dependencies:** `FastLED`, `Encoder`, `Preferences`.
|
|
3. **Build Flags:** - `-D SHOW_BORDER=1` (Enables blue frame)
|
|
- `-D SHOW_BORDER=0` (Full-screen board mode)
|