Skip to content

jcuhnoio/focs-final

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Turing Machine Visualizer - Technical Walkthrough

Architecture Overview

The application is built as a React-based web interface for visualizing and interacting with a Turing machine simulation. The project is structured around several key components:

├── TuringMachine.js         # Main container component
├── TuringMachineClass.js    # Core Turing machine logic
├── Components
│   ├── Tape.js             # Visual tape representation
│   ├── StateViewer.js      # Current state display
│   ├── PlaybackControls.js # Execution controls
│   └── TuringMachineConfig # Machine configuration editor

Core Logic Implementation

TuringMachineClass

The backbone of the simulation is implemented in TuringMachineClass.js. This class handles the core Turing machine operations:

  • State Management: Tracks current state, tape contents, and head position
  • Transition Logic: Implements the state transition function (δ)
  • Execution Control: Handles step-by-step execution and termination conditions

Key methods include:

stepTM(machine, config) {
  // Finds and executes valid transitions based on current state and tape symbol
  // Returns array of possible next configurations
}

isAcceptTM(machine, config) {
  // Checks if current state is an accepting state
}

isDoneTM(machine, config) {
  // Checks if machine has reached a terminal state (accept/reject)
}

User Interface Components

1. Tape Component

The tape visualization (Tape.js) provides a scrolling view of the Turing machine tape:

  • Uses CSS transforms for smooth animation of tape movement
  • Implements infinite tape simulation with dynamic cell generation
  • Highlights the current head position with visual feedback

2. PlaybackControls

Manages execution flow with features like:

  • Step forward/backward
  • Play/pause continuous execution
  • Speed control
  • Input loading
  • Machine reset

3. StateViewer

Provides real-time feedback about:

  • Current state
  • Symbol under head
  • Current transition
  • Next state
  • Final state visualization (accept/reject)

4. TuringMachineConfig

Handles machine configuration with:

  • JSON-based configuration editor
  • Validation of machine definitions
  • Configuration reset capability
  • Error reporting

State Management

The application uses React's useState and useRef hooks for state management:

// Core state elements in TuringMachine.js
const [tape, setTape] = useState([]);
const [headPosition, setHeadPosition] = useState(0);
const [history, setHistory] = useState([]);
const [machineState, setMachineState] = useState("initial");

Visual Design

The UI implements a neumorphic design system with:

  • Soft shadows and highlights
  • Consistent color palette defined in CSS variables
  • Smooth transitions and animations
  • Responsive layout using CSS Grid

Key visual features:

:root {
  --primary: #0A2463;
  --secondary: #3E92CC;
  --background: #ECF0F3;
  --accent: #D8315B;
  --shadow-dark: rgba(10, 36, 99, 0.15);
  --shadow-light: rgba(255, 250, 255, 0.7);
}

Key Features

  1. Step-by-Step Execution

    • Forward and backward stepping through computation
    • Visual feedback for each transition
  2. Configuration Management

    • JSON-based machine definition
    • Real-time validation
    • Error reporting
    • Default configuration for quick start
  3. Visual Feedback

    • Animated tape movement
    • State transitions
    • Accept/reject animations
    • Current state highlighting
  4. Playback Control

    • Variable speed execution
    • Play/pause functionality
    • Reset capability
    • Input modification

Example Machine Configuration

const machine = {
  states: [1, 2, 3, 4, 777, 666],
  alphabet: ["a", "b"],
  tape_alphabet: ["a", "b", "X", "_"],
  start: 1,
  accept: 777,
  reject: 666,
  delta: [
    [1, "a", 2, "X", 1],  // State 1, read 'a': go to state 2, write 'X', move right
    // ... additional transitions
  ]
};

Usage Flow

  1. User inputs string or loads configuration
  2. Machine initializes with input on tape
  3. User can:
    • Step through computation
    • Run continuous execution
    • Modify speed
    • Reset machine
    • Load new input
  4. Visual feedback shows computation progress
  5. Machine terminates with accept/reject animation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors