Skip to content

NirbhikKumawat/GoMinesweeper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minesweeper TUI

A high-performance, terminal-based Minesweeper game built with Go. This project demonstrates a professional CLI architecture using the "Golden Stack" of Go terminal development: Cobra, Viper, and Bubble Tea.

Technical Stack

  • Language: Go (1.21+)
  • CLI Framework: Cobra (Standard for Kubernetes/Docker CLIs)
  • TUI Engine: Bubble Tea (Functional state management)
  • Styling: Lip Gloss & ANSI Escape Sequences
  • Configuration: Viper

Architectural Overview

This project follows the Standard Go Project Layout to ensure a strict separation of concerns:

Layer Package Responsibility
CLI cmd/ Handles flag parsing (--mines, --rows) and command execution.
Logic internal/engine/ Pure game logic: mine placement, neighbor counting, and flood-fill algorithms.
UI internal/ui/ The "View" layer. Implements the Bubble Tea Update/View lifecycle.

Design Patterns Used

  • Model-View-Update (MVU): Used via Bubble Tea to handle UI states without side effects.
  • Dependency Injection: The Game Engine is injected into the UI Model, making the core logic testable without a terminal.
  • Encapsulation: All game internals are kept in internal/ to prevent external package leakage.

Key Features

  • In-Place Rendering: Uses ANSI escape codes for smooth, flicker-free terminal updates.
  • APT-Style Progress Bar: Real-time visual feedback on board clearance using the bubbles/progress component.
  • Dynamic Difficulty: Fully configurable board dimensions and mine density via CLI flags.
  • Color-Coded Interface: High-contrast ANSI colors for numerical proximity and hazard warnings.

Getting Started

Installation

go install

Usage

# Start with default settings (10x10, 12 mines)
minesweeper
# Custom difficulty
minesweeper --rows 15 --cols 20 --mines 40

Engineering Challenges Solved

  1. The Recursive Reveal (Flood Fill) Implemented an optimized flood-fill algorithm that automatically clears empty areas when a "0" cell is revealed. This ensures the game feels fluid and follows classic Minesweeper mechanics.
  2. State Management in TUI Managed the transition between "Input Mode" (typing coordinates) and "Action Mode" (revealing/flagging) within the Bubble Tea event loop, ensuring a 0-latency user experience.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors