You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An advanced, beautifully colorized terminal-based implementation of the classic **Dots & Boxes** pen-and-paper game. Written in pure Python, it supports both local two-player matches and matches against a smart heuristic AI with three distinct difficulty levels.
4
+
5
+
---
6
+
7
+
## 🚀 Features
8
+
9
+
- 🎨 **Vibrant Terminal Styling**: Uses ANSI color escape codes for rendering player blocks, lines, points, and turns in eye-catching colors (Blue, Red, Yellow, Cyan, Green).
10
+
- 👥 **Multiple Game Modes**:
11
+
-**Player vs Player**: Battle locally against a friend.
12
+
-**Player vs AI**: Pit your skills against a computer opponent.
13
+
- 🧠 **Smart AI Opponent**: Features three AI levels utilizing custom decision-making heuristics:
14
+
- 🟢 **Easy**: Makes completely random moves.
15
+
- 🟡 **Intermediate**: Prioritizes completing a box and avoids leaving dangerous 3-sided boxes that would allow the player to score.
16
+
- 🔴 **Hard**: Scores all available moves dynamically, prioritizing game winning configurations, blocking player gains, and positioning itself strategically.
17
+
- 📏 **Custom Board Sizes**: Play on boards ranging from `2x2` up to `8x8` dots.
18
+
- ⚙️ **Accurate Ruleset**: Completing a box grants the scoring player an immediate **extra turn**!
19
+
- 🛡️ **Robust Validation**: Built-in protections against out-of-bounds coordinates, duplicate moves, invalid choices, and negative inputs.
20
+
21
+
---
22
+
23
+
## 🛠️ Requirements
24
+
25
+
-**Python 3.x**
26
+
- No external libraries are needed (uses standard Python library built-in modules: `random`, `time`).
27
+
-*Note: Works best in terminal environments that support ANSI color output.*
28
+
29
+
---
30
+
31
+
## ▶️ How to Run
32
+
33
+
1. Navigate to the game directory:
34
+
```bash
35
+
cd games/Dots-Boxes-AI
36
+
```
37
+
2. Run the script:
38
+
```bash
39
+
python Dots-Boxes-AI.py
40
+
```
41
+
42
+
---
43
+
44
+
## 🎮 Gameplay Guide
45
+
46
+
### Objective
47
+
Draw lines between adjacent dots on the grid. When a player draws the fourth line closing a `1x1` box, they score a point and earn another turn. The player with the most boxes filled when no more lines can be drawn wins!
48
+
49
+
### Playing a Turn
50
+
1. The board is printed showing dots (`•`), drawn horizontal lines (`━━`), drawn vertical lines (`┃`), and completed boxes (`■`).
51
+
2. Input the line direction: `h` for horizontal or `v` for vertical.
52
+
3. Input the **Row** and **Column** coordinates of the line:
53
+
- For **Horizontal** lines: Row range is `0 to size`, Col range is `0 to size-1`.
54
+
- For **Vertical** lines: Row range is `0 to size-1`, Col range is `0 to size`.
55
+
56
+
---
57
+
58
+
## 📸 Sample Board Render
59
+
60
+
```text
61
+
• • •
62
+
┃■ ┃
63
+
•━━• •
64
+
┃
65
+
• •━━•
66
+
```
67
+
68
+
*Note: In the actual terminal, the dots, lines, and boxes are dynamically colored blue for Player 1 and red for Player 2/AI.*
69
+
70
+
---
71
+
72
+
## 📁 File Structure
73
+
74
+
```text
75
+
Dots-Boxes-AI/
76
+
├── Dots-Boxes-AI.py
77
+
└── README.md
78
+
```
79
+
80
+
---
81
+
82
+
## 👤 Author
83
+
84
+
Contributed as part of GSSoC (GirlScript Summer of Code).
0 commit comments