Go Design Pattern: Chain of Responsibility

    📚 Go Design Patterns 🎯Behavioral Pattern ← Command Pattern 📋 All Patterns Observer Pattern → What is Chain of Responsibility? The Chain of Responsibility pattern is a behavioral design pattern that allows you to pass requests along a chain of handlers. Each handler decides whether to process the request or pass it to the next handler in the chain. This pattern decouples the sender of a request from its receivers by giving multiple objects a chance to handle the request. ...

    January 15, 2025 · 13 min · Rafiul Alam

    Ebiten Game Development: First Steps

    Ebiten Game Development Series: Part 1: First Steps | Part 2: Core Concepts → What is Ebiten? Ebiten is a dead-simple 2D game engine for Go. Unlike heavyweight engines with complex editors and asset pipelines, Ebiten gives you a minimalist foundation: a game loop, a way to draw pixels, and input handling. Everything else? You build it yourself. This simplicity is Ebiten’s superpower. You’re not fighting an editor or memorizing a sprawling API. You write Go code that runs 60 times per second and draws rectangles. From those humble beginnings, you can build anything from Pong to procedurally generated roguelikes. ...

    December 15, 2024 · 12 min · Rafiul Alam

    Mastering Go Concurrency: The Coffee Shop Guide to Goroutines

    Go Concurrency Patterns Series: Series Overview | Goroutine Basics | Channel Fundamentals Introduction: Welcome to Go Coffee Shop Imagine running a busy coffee shop. You have customers placing orders, baristas making drinks, shared equipment like espresso machines and milk steamers, and the constant challenge of managing it all efficiently. This is exactly what concurrent programming in Go is like - and goroutines are your baristas! In this comprehensive guide, we’ll explore Go’s concurrency patterns through the lens of running a coffee shop. By the end, you’ll understand not just how to write concurrent Go code, but why these patterns work and when to use them. ...

    December 15, 2024 · 30 min · Rafiul Alam

    Go Design Pattern: Iterator

    📚 Go Design Patterns 🎯Behavioral Pattern ← Observer Pattern 📋 All Patterns State Pattern → What is Iterator Pattern? The Iterator pattern provides a way to access elements of a collection sequentially without exposing the underlying representation. It’s like having a remote control for your TV - you don’t need to know how the channels are stored internally, you just press “next” to move through them. ...

    November 13, 2024 · 11 min · Rafiul Alam

    Managing UI Navigation with Pushdown Automata in Ebitengine

    The UI Navigation Problem Game UI often involves stacked screens: you open a pause menu, then settings, then graphics options, then a confirmation dialog. Each screen needs to: Pause the screen beneath it Handle input independently Resume the previous screen when closed Maintain state across transitions Simple state machines fall short here. You need something that can track a stack of states. Enter the pushdown automaton. What is a Pushdown Automaton? A pushdown automaton is a state machine with a stack. Instead of just transitioning between states, you can: ...

    November 3, 2024 · 8 min · Rafiul Alam

    Saving Game State: Implementing the Memento Pattern with encoding/gob

    The Save/Load Problem Every game needs to save player progress. But how do you capture the entire game state without exposing internal implementation details? How do you support undo/redo, time travel debugging, or replay systems? The Memento pattern solves this by capturing and externalizing an object’s internal state without violating encapsulation. Combined with Go’s encoding/gob package, you get powerful, type-safe serialization for game saves, undo systems, and more. The Naive Approach Here’s what not to do: ...

    October 12, 2024 · 9 min · Rafiul Alam

    Goal-Oriented Action Planning (GOAP): Writing Smarter NPCs in Go

    Beyond Scripted AI Most game NPCs follow scripted behaviors or state machines: “If enemy seen, attack. If health low, flee.” While predictable and easy to implement, these approaches lack the intelligence to adapt to changing circumstances. What if your NPC could plan their own actions based on goals? Goal-Oriented Action Planning (GOAP) empowers NPCs to dynamically create plans to achieve their goals. Used in games like F.E.A.R. and The Sims, GOAP creates emergent, intelligent behaviors that feel surprisingly alive. ...

    September 19, 2024 · 9 min · Rafiul Alam

    Pipeline Patterns: Streaming Data Processing with Goroutines

    The Power of Streaming Pipelines Imagine processing a million log entries. The naive approach loads everything into memory, processes it, then outputs results. But what if you don’t have enough RAM? What if you want results streaming in real-time? Pipeline patterns break complex processing into stages connected by channels. Data flows through the pipeline, with each stage transforming it concurrently. It’s Unix pipes meets goroutines-and it’s beautiful. The Sequential Approach Here’s what we’re moving away from: ...

    August 30, 2024 · 8 min · Rafiul Alam

    Go Design Pattern: State

    What is State Pattern? The State pattern is a behavioral design pattern that allows an object to alter its behavior when its internal state changes. It appears as if the object changed its class. Think of it like a vending machine - it behaves differently when it’s waiting for coins, has coins inserted, is dispensing a product, or is out of stock. Each state has its own set of valid operations and transitions. ...

    August 5, 2024 · 11 min · Rafiul Alam

    Go Design Pattern: Template Method

    What is Template Method Pattern? The Template Method pattern is a behavioral design pattern that defines the skeleton of an algorithm in a base class and lets subclasses override specific steps without changing the algorithm’s structure. Think of it like a recipe - the overall cooking process is the same (prepare ingredients, cook, serve), but the specific steps can vary depending on what you’re making. In Go, since we don’t have traditional inheritance, we implement this pattern using composition and interfaces, which actually makes it more flexible and idiomatic. ...

    July 10, 2024 · 11 min · Rafiul Alam