How uchiha-itachi0/self_driving_car works
Main Components
• Core Simulation Engine – Represented by src/index.js which initializes and orchestrates the simulation.
• AI Module – Under src/AI, this component includes:
• NeuralNetwork.js for the feedforward neural network.
• Population.js for handling genetic algorithm operations.
• SmartCar.js which links the neural network to the car’s behavior.
• Game Module – Under src/Game, includes:
• Car.js (game object for the car, likely with simulation physics).
• Track.js (defines the course boundaries and track layout).
• Geometry Module – Under src/Geometry, provides essential tools:
• Sketch/UI Module – Under src/Sketch:
• Contains multiple view files (e.g., gameOver.js, human.js, menu.js) that manage different states or screens of the simulation.
• Sketch/state.js and an index.js for overall UI management.
• Utility Module – Under src/Utils:
• Files like Ray.js and Sensors.js that likely help in sensor simulation and raycasting.
Relationships and Interactions
• The simulation begins in src/index.js where the game loop integrates multiple modules.
• The Game Module (Car and Track) represents the scene; here, each Car object is controlled by an AI component.
• The AI Module controls car behavior:
• SmartCar uses sensor data (from src/Utils/Sensors.js and possibly Geometry computations) as input for its NeuralNetwork.
• The network computes motor control signals which then determine the car’s acceleration and steering.
• The Genetic Algorithm in Population.js interacts with multiple SmartCar instances:
• It evaluates performance per generation.
• It selects, crosses over, and mutates network weights to produce a new population.
• The Sketch Module organizes user views:
• Different screens (e.g., initial, training, replay, game over) indicate the state of the simulation and offer user interaction.
• The Utility and Geometry modules provide supporting functions (like collision detection or sensor raycasting) and are used across other modules.
Architectural Patterns and Design Principles
• Modular Organization – Each folder (AI, Game, Geometry, Sketch, Utils) encapsulates a distinct responsibility.
• Separation of Concerns – AI computations, game physics, UI states, and utility functions are clearly delineated.
• Feedback Loop – There is a cyclical process where sensor inputs feed into the neural network, which then alters the game state, and the outcomes are used to train via the genetic algorithm.
Incorporate Relevant Technologies and Frameworks
• Pure JavaScript – The project is implemented using standard JavaScript (likely run in a browser given the index.html).
• Frontend Rendering – The simulation views under src/Sketch indicate potential use of a canvas or similar rendering library (possibly p5.js or native HTML5 Canvas).
• Algorithm Implementation – The feedforward Neural Network and Genetic Algorithm are key AI components.
• Sub-components if necessary (e.g., within the AI module, show the breakdown into NeuralNetwork, Population, and SmartCar).
• That each view or UI state (from src/Sketch/Views) is connected to show how user interactions and simulation states are rendered.