Programming Strategies

Programming Strategies

Building on the conceptual foundation of Grid-Based Games, this part introduces the programming strategies that bring grids to life in code. Developed and refined through workshops, classroom projects, and the SoftwareX research cycle, these strategies provide concrete ways to organize logic, interaction, and visualization in p5.js using the p5.quadrille.js library.

Each strategy highlights a single design idea—aggregation, layering, temporal evolution, or algebraic combination—and shows how declarative, functional, and object-oriented approaches naturally converge through play. Together, they form a practical framework for learning and designing through composition: small, modular elements that combine to model increasingly complex grid behaviors.

Overview of Strategies

This part opens with Features of a Quadrille, which establishes the quadrille as a programmable grid—linking data, state, and display. It introduces core access and iteration methods that turn the grid into an active model of computation, forming the basis for all strategies that follow. Subsequent chapters expand these ideas through increasingly rich forms of composition and abstraction.

  • Aggregated states — Keep all play data in a single quadrille. Cells hold symbols or values (e.g., X/O), making turn logic and pattern checks straightforward without juggling multiple boards.

  • Layered boards — Split concerns into separate quadrilles (per-player, visibility, hints). Layers compose visually, keeping rules clean and values distinct.

  • Timelines — Record snapshots of the grid to track its evolution. Enables undo/redo, replays, and branching histories.

  • Algebra — Combine grids with boolean logic (OR / AND / XOR / NOT). Apply per-cell operators to merge, mask, or clear patterns cleanly.

  • Cell effects — Store pure display functions in cells. This display contract enables per-cell highlights, styling, and procedural animation.

  • Cell objects — Store objects with state and behavior in cells (units, items). Methods localize interaction (display, move), improving code reuse and clarity.

  • Polymorphic cell objects — Extend entities through a shared interface. Inheritance or duck typing allows diverse objects to interoperate under unified rules.

  • Bitboards — Represent grids as BigInt masks for fast shifts and logic tests. Integrate low-level efficiency with high-level readability by converting to and from Quadrilles.

Most grid-based games can be built by composing these strategies in different ways—each reinforcing the others while maintaining clarity, modularity, and expressiveness.