Skip to content

DevWonder01/neural-byte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neural Byte

Neural Byte is a high-performance 2D evolutionary predator-prey simulation written in Rust. It utilizes the Macroquad graphics engine for real-time hardware-accelerated rendering and a custom feedforward neural network implementation to drive agent behavior and steering.

Over time, prey adapt to locate food while dodging predators, and predators evolve more efficient tracking algorithms to hunt prey. The simulation features real-time interactive parameter adjustments and a detailed neural inspector.

alt text

Features

  • Feedforward Neural Networks: Each agent is driven by a custom multi-layer perceptron. Hidden layers use Rectified Linear Unit (ReLU) activations for hidden nodes and Hyperbolic Tangent (Tanh) activations for steering and throttle outputs.
  • Genetic Evolution: Agents reproduce based on energy surplus. Offspring inherit mutations in weights and biases derived from a Gaussian distribution to simulate selection pressure.
  • Real-Time Telemetry Dashboard: Includes live population graph tracking and interactive sliders to control simulation speed, mutation rate, and baseline population limits.
  • Live Neural Network Inspector: Clicking on any prey or predator highlights the agent and displays its neural network topology, weight linkages, active biases, sensory inputs, and motor outputs.
  • Steering-Based Physics: Agents utilize local coordinate conversions to steer toward food or away from threat vectors.

Controls and Dashboard Panel

The right-hand side panel provides full interactive control over the simulation:

  • Simulation Speed: Adjusts the number of physics steps executed per frame (1x to 8x).
  • Mutation Amount: Controls the standard deviation of Gaussian noise applied to weights and biases during reproduction.
  • Reset Arena: Completely wipes the simulation and reinstates the default starting populations.
  • Sensors ON/OFF: Toggles rendering of sensory lines indicating which targets an agent is tracking.
  • Glow ON/OFF: Toggles glowing visual aesthetics around food and agents.
  • Spawn Buttons: Spawn batches of 10 prey or 3 predators immediately.
  • Population Baseline Sliders: Set the minimum population count for prey and predators. If the count drops below this value, the simulation automatically spawns new agents.

System Architecture

Neural Network Structure

  • Prey Brain (Input: 4, Hidden: 8, Output: 2):
    • Inputs: Local relative direction to the nearest food source (X, Y) and nearest predator (X, Y).
    • Outputs: Left/Right Steering Force, Speed Throttle (acceleration/deceleration).
  • Predator Brain (Input: 3, Hidden: 8, Output: 2):
    • Inputs: Local relative direction to the nearest prey (X, Y) and proximity to it.
    • Outputs: Left/Right Steering Force, Speed Throttle.

Evolutionary Dynamics

  • Prey: Consumes food particles to gain energy. Spawns an offspring after reaching an energy threshold of 100.0, passing its mutated weights and biases to the child.
  • Predator: Loses energy over time due to metabolism. Consumes prey to gain 220.0 energy. Spawns an offspring after reaching an energy threshold of 700.0.

Installation and Execution

Prerequisites

Ensure you have Rust and Cargo installed. If not, follow the instructions on rustup.rs.

Running the Project

Clone the repository and run the project using Cargo:

cargo run --release

The release flag is recommended to ensure optimal physics and collision performance at high simulation speeds.

Key Dependencies

  • macroquad: A simple and easy-to-use game library in Rust.
  • rand: Random number generators and distribution functions.
  • rand_distr: For Normal (Gaussian) distribution calculations used during mutation.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages