Back to Archive

Pattern-Match: Finite State Logic Engine

Core Logic & State Implementation

The Engineering Objective

This project serves as an exploration of Finite State Machines (FSM) in a frontend environment. The goal was to build a robust validation engine that manages multiple game states—Ready, Sequence-Playback, User-Input, and Error-Handling—while maintaining a deterministic sequence of events.

Core Logic & State Orchestration

The engine focuses on the reconciliation between a generated 'Source of Truth' and asynchronous user inputs.

  • Dynamic Sequence Generation: Built a randomized generator that appends to an array-based state, ensuring pattern persistence across rounds.
  • Input Validation Logic: Implemented a pointer-based comparison algorithm that validates user input against the sequence in real-time ($O(1)$ per click).
  • State Transitions: Managed the application flow through distinct logic blocks to prevent race conditions during the transition from 'playback' to 'input' modes.

Outcome

Successfully implemented a complex state-driven UI that handles dynamic scaling difficulty. The project strengthened my understanding of event-driven programming and the importance of maintaining clear state boundaries in logic-heavy frontend applications.