How peter-abah/rb_chess works
Project type and purpose
• This is an open-source Ruby library (gem) that implements a full chess engine (rules, move generation/validation, serialization) and provides a command-line interface (CLI) for playing games.
• It exposes a public API (RbChess::Game, Board, Move, etc.) and a CLI entry point (bin/rb_chess → RbChess::CLI::CLI).
Main architectural components
a. Core Engine
• RbChess::Game
• RbChess::Board
• RbChess::Position
• RbChess::Move, MoveSet
• RbChess::Pieces (king, queen, rook, bishop, knight, pawn, piece_constants)
• RbChess::GameModules
• MoveGenerator
• MoveParser
• MoveValidator
• CastlingRights, FenParser, Errors
b. Serialization layer
• FEN parser/generator
• JSON and binary serialization (GameSaver)
c. CLI Layer
• bin/rb_chess (executable stub)
• RbChess::CLI::CLI (main loop, user input)
• RbChess::CLI::Players (player abstractions)
• RbChess::CLI::GameSaver (persist/restore game state)
d. Test Suite (RSpec)
• spec/* mirror core structure
Component relationships and data flow
• CLI → invokes → Game
• Game → composes → Board + Position + CastlingRights
• When make_move is called:
• MoveParser parses string → Move object
• MoveValidator checks legality against Board + GameModules
• MoveGenerator produces all possible moves
• Board updates Position + Pieces
• Game updates turn, move history
• Serialization:
• GameSaver ↔ Game (to_fen, from_fen, to_json, from_json, to_binary, from_binary)
• FENParser is used by both core and CLI to load/save state
Architectural patterns and design principles
• Modular design: Each responsibility isolated into its own file/namespace (Single Responsibility Principle)
• Use of Ruby modules to namespace components (RbChess, RbChess::CLI, RbChess::GameModules)
• Layered architecture: Core engine layer → Serialization layer → CLI layer
• Dependency inversion: high-level CLI depends on abstractions (Game API) rather than low-level modules
Elements
• Clear labels for each component (use class/module names)
• User input → CLI::CLI
• CLI::CLI → Game API
• Game → Board, MoveParser, MoveValidator, MoveGenerator
• GameSaver ↔ Game
• Core engine → FENParser
• Blue rectangles for core engine modules
• Green for CLI components
• Yellow for serialization/FENParser