🔴 4 in a Row – Bitboard + PVS

A polished 4-in-a-Row puzzle game (10×10 grid, win with 4) built with Python and PyQt5.

Features a strong AI engine using Principal Variation Search with iterative deepening, bitboard

evaluation, and killer-move heuristics.

 

📥 Download & Run (No Python needed)

Platform       File      Instructions

🪟 Windows          4_in_a_Row.exe    Download and double-click to run

🍎 macOS   4_in_a_Row.app   Open the .app bundle — right-click → Open if blocked by Gatekeeper

🐧 Linux      4_in_a_Row (binary)       chmod +x 4_in_a_Row && ./4_in_a_Row

 

Linux note: If the app doesn't start, make it executable first:

chmod +x 4_in_a_Row

./4_in_a_Row

 

🎮 How to Play

Click the ↓ arrow above a column to drop your stone (🔴 Red).

Get 4 in a row — horizontally, vertically, or diagonally — to win.

The winning stones are highlighted in gold when the game ends.

Controls

Action           Function

Click ↓ button        Drop stone in that column

Ctrl+Z / Menu → Undo    Take back your last move (+ AI's move)

Menu → New Game         Start a new game

 

 

Features

    • 10×10 grid — more space, more strategy than the classic 7×6 board

    • 3 AI difficulty levels with very different strength and thinking time

    • Winning line highlighted in gold — see exactly how the game was decided

    • Undo (Ctrl+Z) — takes back your move and the AI's reply together

    • Human vs. Human mode — play against a friend on the same computer

    • Persistent settings — language, difficulty and mode are remembered on next launch

    • 14 languages — switchable in-game at any time from the menu

 

🤖 AI Difficulty Levels

Level  Search Depth          Thinking Time         Strength

Easy   6         1.0 s   Makes occasional mistakes

Hard  12       2.5 s   Solid, rarely misses threats

Expert           16       5.0 s   Recognizes all threats including gaps (x_xx)

 

The AI uses Principal Variation Search (PVS) with:

    • Iterative deepening

    • Transposition table with exact/lower/upper bound flags

    • Killer-move heuristic

    • Correct bitboard win detection with row-boundary masks

    • Window-based evaluation that detects gap threats like x_xx and xx_x

 

🌍 Languages

Switch language any time from the Language menu — saved automatically.

                                   

🇩🇪 Deutsch   🇬🇧 English     🇫🇷 Français   🇪🇸 Español

🇮🇹 Italiano     🇳🇱 Nederlands        🇵🇱 Polski        🇵🇹 Português

🇷🇺 Русский  🇺🇦 Українська        🇬🇷 Ελληνικά 🇭🇺 Magyar

🇹🇷 Türkçe      🇨🇿 Čeština                

 

Adding a new language

Open 4_in_a_Row.py and add a new entry to the LANG dictionary — the menu entry appears automatically:

"Svenska": {

    "flag":             "🇸🇪",

    "title":            "4 i rad – Bitboard + PVS",

    "menu_mode":        "Läge",

    "menu_diff":        "Svårighetsgrad",

    "menu_lang":        "Språk",

    "menu_new":         "Nytt spel",

    "menu_undo":        "Ångra (Ctrl+Z)",

    "mode_hvh":         "Människa vs. Människa",

    "mode_hvc":         "Människa vs. Dator",

    "diff_easy":        "Lätt",

    "diff_hard":        "Svår",

    "diff_exp":         "Expert",

    "status_your_turn": "Din tur (Röd)",

    "status_p1":        "Spelare 1 (Röd) spelar",

    "status_p2":        "Spelare 2 (Grön) spelar",

    "status_ai":        "Datorn tänker…",

    "win_p1":           "Spelare 1 (Röd) vinner!",

    "win_p2":           "Spelare 2 (Grön) vinner!",

    "win_you":          "Du vinner!",

    "win_ai":           "Datorn vinner!",

    "draw":             "Oavgjort!",

    "dlg_title":        "Spelet slut",

    "dlg_question":     "Spela igen?",

},

Settings are stored per platform:

Platform       Path

Windows      %APPDATA%\4inARow\settings.json

macOS          ~/Library/Application Support/4inARow/settings.json

Linux  ~/.config/4inARow/settings.json

 

 

🐍 Run from Source

Requirements: Python 3.8+ and PyQt5

pip install PyQt5

python 4_in_a_Row.py

 

📄 License

MIT License — free to use, modify and distribute.