$ show olistic/warriorjs
WarriorJS is a terminal-based educational game that teaches JavaScript and TypeScript through interactive coding challenges. Players write a `Player` class with a `playTurn(warrior)` method to control a warrior navigating grid-based towers filled with enemies, captives, and stairs. The game runs as a CLI application using Ink (React for terminal UI) and relies on a sandboxed code execution environment via Node's `vm` module and esbuild. The monorepo structure includes a CLI app, game engine (`@warriorjs/core`), abilities library (`@warriorjs/abilities`), units library (`@warriorjs/units`), scoring module, spatial math helpers, effects, and two sample towers. The codebase demonstrates clean architecture with well-separated concerns, extensive test coverage, and reusable patterns such as the ability/effect binding factory and sensed space wrappers. However, the project has been inactive since 2018 (last release v0.14.0), the documentation website uses the deprecated Docusaurus v1, and there are some mixed module system usages. Despite being stale, the game engine and ability system remain functional and could be extracted for similar turn-based coding games or sandboxed code execution.
The LLM identified 5 files worth highlighting for reuse:
Re-exports all ability classes and demonstrates a consistent factory pattern where each ability is instantiated via a static `with(config)` method returning a `[AbilityClass, config]` tuple. This pattern is reusable for any plugin-based system requiring configurable, composable components (e.g., game abilities, effects, or event handlers). The abilities themselves (Attack, Feel, Walk, etc.) implement a clean `Sense`/`Action` hierarchy from `@warriorjs/core`, making them self-contained and testable.
Provides a reusable sandboxed code execution mechanism for user-provided player code. It uses `esbuild` to transpile the code (supports JS/TS, JSX) and then evaluates it within a Node `vm.createContext` sandbox. This pattern is isolated (only imports `esbuild` and `vm`) and can be extracted into any project needing safe execution of arbitrary user code with limited API exposure. The sandbox context is configurable, allowing fine-grained control over available globals.
Implements a `Position` class for grid-based spatial logic: managing coordinates, orientation, and relative direction calculations. It provides methods like `rotateRelativeOffset` to convert relative directions (forward, backward) into absolute offsets based on the unit's facing direction. This is a self-contained utility module (only depends on `@warriorjs/spatial` constants) that can be reused in any 2D grid-based game or simulation requiring direction-relative movement.
Defines a `Space` object that wraps the raw floor cell and provides a restricted interface (`SensedSpace`) when accessed from player code. The `as(unit)` method creates a proxy that limits which properties and methods are exposed (e.g., hiding the floor reference, restricting abilities). This pattern is reusable for any game or simulation where you need to present a safe, read-only view of internal state to external code, protecting the core model from accidental or malicious modification.
Implements a `usePlayback` hook that manages replay state using a `useReducer` pattern. It controls playback speed, cursor position, mode (playing/paused/reviewing), and event dispatch for turn-by-turn animation. The reducer is pure, well-typed, and handles edge cases like end-of-replay and speed changes. This can be extracted as a generic playback state machine for any animated replay system (e.g., game replays, video players, step-through debugging).