Skip to content

Scientific exploration of program debugging through 2048-cli. Features 29+ experiments in TTY control, memory inspection, LLDB automation, and AI integration.

License

Notifications You must be signed in to change notification settings

jwalsh/2048-cli-debug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

70 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

2048 CLI Debug

Learning to interact with running programs through TTY, screen, expect, and eventually GDB/LLDB. Using 2048-cli as a test case for real-time program control and state inspection.

The score doesnโ€™t matter - the interaction does! ๐ŸŽฎ

This project documents the journey from failed Python abstractions to successful expect scripts, with the ultimate goal of debugger-based program control.

๐ŸŽฎ Game Screenshots

Starting Position

Score: 28 (+12)
   Hi: 932
-----------------------------
|    2 |      |    4 |    8 |
|      |      |      |    8 |
|      |      |      |      |
|      |      |      |      |
-----------------------------

High Score Achievement

Score: 800 (High Score!)
-----------------------------
|      |      |      |    4 |
|      |      |      |    8 |
|      |      |    4 |   16 |
|      |    8 |   16 |    8 |
-----------------------------

Achieved using the Down-Right Strategyโ„ข

๐Ÿš€ Features

  • LLDB Debug Scripts: Automated board state dumps, memory inspection, and gameplay analysis
  • Emacs Integration: Custom mode with compilation, debugging, and visualization support
  • Memory Analysis: Tools for inspecting game state and board memory layout
  • AI Analysis: Observe and analyze AI gameplay patterns
  • Build Automation: Enhanced Makefile with debugging and source management targets
  • TTY Controller: Automated gameplay with complexity detection and manual inspection points
  • Board Analyzer: Real-time complexity scoring and strategy suggestions
  • Scientific Experiments: Rigorous experimental framework in experiments/

๐Ÿ“‹ Requirements

ToolVersionRequiredNotes
C CompilerC99+โœ…gcc/clang
LLDB14.0+โœ…Primary debugger
Emacs25.1+โญ•For IDE features
Make3.81+โœ…Build system
etagsAnyโญ•Code navigation
screen4.0+โญ•TTY capture
tmux3.0+โœ…TTY interaction
Python3.8+โœ…Analysis scripts
uv0.1+โœ…Python environment

๐Ÿ› ๏ธ Installation

# Clone the repository
git clone https://github.com/jwalsh/2048-cli-debug.git
cd 2048-cli-debug

# Build the game
cd 2048-cli-0.9.1
make

# Build with debug symbols
make CFLAGS="-g -O0"

# Generate tags for navigation
make etags

๐ŸŽฏ Quick Start

Running the Game

# Play interactively
./2048

# Watch AI play
./2048 --ai

# Custom board size
./2048 --size 5

Simple Board State Display

To quickly see what a 2048 board looks like:

# One-liner to show board state
echo -e "Score: 0\n   Hi: 0\n$(printf '%s\n' -{1..29} | tr -d ' ')\n|    2 |      |      |      |\n|      |      |      |      |\n|      |      |      |      |\n|      |      |      |    2 |\n$(printf '%s\n' -{1..29} | tr -d ' ')"

Output:

Score: 0
   Hi: 0
-----------------------------
|    2 |      |      |      |
|      |      |      |      |
|      |      |      |      |
|      |      |      |    2 |
-----------------------------

TTY Controller

# Set up Python environment
uv sync

# Run automated test with manual inspection points
uv run python -m tty_manual.manual_test_runner \
  --spam-moves 50 \
  --check-interval 10 \
  --threshold 60

# Analyze a board snapshot
uv run python -m tty_manual.board_analyzer board_test.txt

# Interactive TTY reader
uv run python -m tty_manual.tty_reader --interactive

Debugging

# Basic debugging session
lldb ./2048 -s debug.lldb

# Interactive debugging with custom commands
lldb ./2048 -s debug-interactive.lldb

# Automated analysis
lldb ./2048 -s debug-automated.lldb

Emacs Integration

Add to your Emacs configuration:

(add-to-list 'load-path "/path/to/2048-cli-debug/2048-cli-0.9.1/")
(require '2048-mode)

Key bindings:

  • C-c C-c - Compile
  • C-c C-d - Debug with LLDB
  • C-c C-r - Run game
  • C-c C-a - Run with AI

๐Ÿ“ Project Structure

2048-cli-debug/
โ”œโ”€โ”€ 2048-cli-0.9.1/         # Game source code
โ”‚   โ”œโ”€โ”€ src/                # C source files
โ”‚   โ”œโ”€โ”€ debug*.lldb         # LLDB scripts
โ”‚   โ”œโ”€โ”€ 2048-mode.el        # Emacs mode
โ”‚   โ””โ”€โ”€ Makefile            # Build configuration
โ”œโ”€โ”€ experiments/            # Scientific experiments
โ”‚   โ”œโ”€โ”€ README.org          # Experiment overview
โ”‚   โ”œโ”€โ”€ exp_007/            # Memory layout discovery
โ”‚   โ”œโ”€โ”€ exp_008/            # Statistical validation
โ”‚   โ”œโ”€โ”€ exp_009/            # Speed baseline
โ”‚   โ”œโ”€โ”€ exp_010/            # Timing validation
โ”‚   โ””โ”€โ”€ ...                 # More experiments
โ”œโ”€โ”€ docs/                   # Documentation
โ”œโ”€โ”€ tty_manual/             # TTY interaction framework
โ”œโ”€โ”€ README.org              # This file
โ”œโ”€โ”€ CONTRIBUTING.org        # Contribution guidelines
โ”œโ”€โ”€ ARCHITECTURE.org        # System architecture
โ””โ”€โ”€ LICENSE                 # MIT License

๐Ÿ”ฌ Scientific Experiments

The experiments/ directory contains rigorous scientific investigations:

Completed Experiments

  • Exp 007: Memory Layout Proof - Discovered grid[col][row] indexing
  • Exp 008: Statistical Validation - Down-right spam distribution
  • Exp 009: Speed Baseline - Found built-in 160ms/move delay
  • Exp 010: Timing Validation - Non-linear timing behavior

Ongoing Research

  • Exp 011: Timing Curve Analysis - Board locking effects
  • Exp 012-016: AI Players - Claude playing strategies
  • Exp 017-020: LLDB Framework - Advanced debugging
  • Exp 021-025: Pattern Analysis - Board representations

See experiments/README.org for detailed results and methodologies.

๐Ÿ” Debug Features

LLDB Scripts

  • debug.lldb: Basic breakpoints with automatic board dumps
  • debug-interactive.lldb: Custom commands (board, raw, state)
  • debug-automated.lldb: AI gameplay analysis
  • debug-symbols.lldb: Symbol and type information

Memory Layout

The game uses a clever memory layout:

  • Single contiguous array for board data
  • 2D pointer array for column access (grid[col][row])
  • Efficient for both cache and iteration

๐Ÿค Contributing

See CONTRIBUTING.org for detailed guidelines on:

  • Understanding the codebase
  • Debugging techniques
  • Emacs workflow
  • Submitting changes

๐Ÿ“š Documentation

๐Ÿ™ Acknowledgments

  • Original 2048-cli by Marc Tiehuis
  • 2048 game concept by Gabriele Cirulli

๐Ÿ“„ License

This project maintains the MIT License from the original 2048-cli. See LICENSE for details.

About

Scientific exploration of program debugging through 2048-cli. Features 29+ experiments in TTY control, memory inspection, LLDB automation, and AI integration.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •