Skip to content

A web-based simulation of human behavior using distinct agent types (Leaders, Influencers, Rebels, Observers) with evolving emotions. Explore social dynamics by adjusting parameters like influence and rebellion. Features AI-powered analysis via Google Gemini API to interpret collective trends and emotional shifts.

Notifications You must be signed in to change notification settings

Barontex1000/my-behavior-sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Human Behavior Simulation

This project presents an interactive web-based simulation designed to model fundamental aspects of human social behavior, including influence, rebellion, and emotional volatility, within a grid-based environment. It features different agent types that interact and influence each other's emotional states, offering a visual representation of complex social dynamics.

Features

  • Dynamic Grid Simulation: Agents move and interact on a visual 30x30 grid.
  • Four Agent Types: Observe the behaviors and interactions of Leaders, Influencers, Rebels, and Observers.
  • Emotional State: Each agent has an emotional state (0 = calm, 1 = panicked) that changes based on interactions and inherent volatility.
  • Configurable Parameters: Adjust key simulation variables like influence strength, rebellion rate, and emotional volatility to see their impact on the system.
  • Real-time Statistics: Monitor the population counts of each agent type and the current simulation cycle.
  • Integrated AI Analysis (Google Gemini API): Obtain real-time, AI-generated insights into the simulation's state and trends, leveraging the Gemini-2.0-flash model.
  • API Key Management: Securely set your Google API Key within the application for AI functionalities.
  • Standard Controls: Start, pause, and reset the simulation as needed.

How to Run

  1. Download the file: Save the Human Behavior Simulation.html file to your local machine.
  2. Open in Browser: Open the Human Behavior Simulation.html file with any modern web browser (e.g., Chrome, Firefox, Edge).
  3. Set Google API Key: For the AI Analysis feature, you will need a Google API Key with access to the Gemini API. Enter your key in the provided input field and click "Set API Key".
    • Note: Your API key is stored only in the browser's session and is not sent to any server other than Google's Gemini API endpoint.

Simulation Mechanics

General

  • Grid System: Agents occupy cells on a wrapped 30x30 grid, meaning they reappear on the opposite side if they move off an edge.
  • Movement: Agents move randomly to an adjacent cell (including diagonals) or can remain stationary in each simulation cycle.
  • Influence: Agents influence their immediate neighbors (Manhattan distance of 1) based on their type and the set parameters. This affects the neighbors' emotional states.
  • Emotional Fluctuation: All agents experience some random emotional volatility, adding a dynamic element to their states.

Agent Types

Each agent type has a distinct role and visual representation:

  • Leader (👑 / Blue Border):
    • Aims to calm other agents, decreasing their emotional level.
    • Their influence strength is governed by the "Influence Strength" parameter.
  • Influencer (📣 / Orange Border):
    • Similar to Leaders, Influencers also aim to calm other agents.
    • Their influence strength is governed by the "Influence Strength" parameter.
  • Rebel (⚡ / Red Border):
    • Aims to agitate other agents, increasing their emotional level.
    • Their agitation strength is governed by the "Rebellion Rate" parameter.
  • Observer (👁️ / Gray Border):
    • Primarily reacts to the environment and other agents but does not actively influence them.
    • Their emotion still fluctuates based on the "Emotional Volatility" parameter.

Emotion

  • An agent's emotional state is a value between 0 (calm) and 1 (panicked).
  • The background fill of an agent's cell visually represents their emotion: whiter for calm, more transparent for panicked.

Controls and Settings

  • Start Button: Begins the simulation.
  • Pause Button: Halts the simulation.
  • Reset Button: Resets the simulation to its initial state, reinitializing all agents and clearing the cycle counter and AI analysis output.
  • API Key Input & Set API Key Button: Used to input and store your Google Gemini API key.

Parameters

  • Influence Strength: Adjusts the calming effect of Leaders and Influencers on their neighbors (0-10).
  • Rebellion Rate: Adjusts the agitating effect of Rebels on their neighbors (0-10).
  • Emotional Volatility: Controls the random fluctuation in all agents' emotional states (0-10).
  • Simulation Speed (ms): Sets the interval (in milliseconds) between each simulation cycle. Lower values mean faster simulations (10-1000 ms).

Live Statistics

  • Cycle: Displays the number of simulation cycles that have passed.
  • Leaders, Influencers, Rebels, Observers: Show the current population count for each agent type.

AI Simulation Analysis

This section utilizes the Google Gemini API to provide an interpretive summary of the ongoing simulation.

  • Get AI Analysis Button: Triggers a call to the Gemini API with current simulation statistics (cycle, agent counts, average emotion).
  • Analysis Output: Displays a concise summary (1-3 sentences) from the AI, interpreting the current state, overall mood, dominant agent types, and potential trends.

Technologies Used

  • HTML5: Provides the structural foundation of the web page.
  • CSS3 (Tailwind CSS): Used for responsive and modern styling, including custom styles for sliders and buttons.
  • JavaScript: Powers the core simulation logic, agent behaviors, canvas rendering, and user interface interactivity.
  • Google Gemini API (gemini-2.0-flash): Integrated for real-time analysis of simulation data, providing interpretative summaries.

About

A web-based simulation of human behavior using distinct agent types (Leaders, Influencers, Rebels, Observers) with evolving emotions. Explore social dynamics by adjusting parameters like influence and rebellion. Features AI-powered analysis via Google Gemini API to interpret collective trends and emotional shifts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages