Function bodies 1,000 total
probability function · rust · L62-L70 (9 LOC)archive/cliffy-alive/src/evolution.rs
pub fn probability(&self) -> f64 {
match self {
MutationType::PointMutation => 0.8,
MutationType::LargeMutation => 0.15,
MutationType::GeneDuplication => 0.02,
MutationType::GeneDeletion => 0.02,
MutationType::Recombination => 0.01,
}
}intensity function · rust · L73-L81 (9 LOC)archive/cliffy-alive/src/evolution.rs
pub fn intensity(&self) -> f64 {
match self {
MutationType::PointMutation => 0.05,
MutationType::LargeMutation => 0.3,
MutationType::GeneDuplication => 1.0,
MutationType::GeneDeletion => 1.0,
MutationType::Recombination => 0.5,
}
}default function · rust · L147-L156 (10 LOC)archive/cliffy-alive/src/evolution.rs
fn default() -> Self {
Self {
generation: 0,
average_fitness: 0.0,
trait_averages: HashMap::new(),
interaction_success_rate: 0.0,
adaptation_speed: 0.0,
diversity_index: 0.0,
}
}new function · rust · L161-L171 (11 LOC)archive/cliffy-alive/src/evolution.rs
pub fn new(strategy: EvolutionStrategy) -> Self {
Self {
strategy,
mutation_rate: 0.05,
selection_strength: 1.0,
learning_rate: 0.1,
trait_memory: HashMap::new(),
interaction_history: Vec::new(),
performance_metrics: PerformanceMetrics::default(),
}
}evolve_organism function · rust · L191-L214 (24 LOC)archive/cliffy-alive/src/evolution.rs
pub fn evolve_organism(&mut self, organism: &mut UIOrganismField, dt: UITime) {
match &self.strategy.clone() {
EvolutionStrategy::NaturalSelection => {
self.apply_natural_selection(organism, dt);
}
EvolutionStrategy::DirectedEvolution { target_traits } => {
self.apply_directed_evolution(organism, target_traits, dt);
}
EvolutionStrategy::UserGuided {
interaction_weights,
} => {
self.apply_user_guided_evolution(organism, interaction_weights, dt);
}
EvolutionStrategy::Hybrid { strategies } => {
for strategy in strategies {
let mut sub_engine = EvolutionEngine::new(strategy.clone());
sub_engine.evolve_organism(organism, dt / strategies.len() as f64);
}
}
}
// Update performance metrics
self.update_performance_metrapply_natural_selection function · rust · L217-L228 (12 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_natural_selection(&mut self, organism: &mut UIOrganismField, dt: UITime) {
// Calculate fitness for each cell based on survival metrics
let mut fitness_scores = HashMap::new();
for ((x, y), cell) in organism.iter_cells() {
let fitness = self.calculate_natural_fitness(cell);
fitness_scores.insert(cell.id(), fitness);
}
// Apply selection pressure based on fitness
self.apply_fitness_selection(organism, &fitness_scores, dt);
}apply_directed_evolution function · rust · L231-L250 (20 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_directed_evolution(
&mut self,
organism: &mut UIOrganismField,
target_traits: &HashMap<String, f64>,
dt: UITime,
) {
// Calculate fitness based on proximity to target traits
let mut fitness_scores = HashMap::new();
for ((x, y), cell) in organism.iter_cells() {
let fitness = self.calculate_trait_fitness(cell, target_traits);
fitness_scores.insert(cell.id(), fitness);
}
// Apply selection pressure
self.apply_fitness_selection(organism, &fitness_scores, dt);
// Apply directed mutations
self.apply_directed_mutations(organism, target_traits, dt);
}Repobility · code-quality intelligence platform · https://repobility.com
apply_user_guided_evolution function · rust · L253-L272 (20 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_user_guided_evolution(
&mut self,
organism: &mut UIOrganismField,
interaction_weights: &HashMap<String, f64>,
dt: UITime,
) {
// Calculate fitness based on user interaction success
let mut fitness_scores = HashMap::new();
for ((x, y), cell) in organism.iter_cells() {
let fitness = self.calculate_interaction_fitness(cell, interaction_weights);
fitness_scores.insert(cell.id(), fitness);
}
// Apply selection pressure
self.apply_fitness_selection(organism, &fitness_scores, dt);
// Learn from interaction patterns
self.apply_interaction_learning(organism, dt);
}calculate_natural_fitness function · rust · L275-L281 (7 LOC)archive/cliffy-alive/src/evolution.rs
fn calculate_natural_fitness(&self, cell: &UICell) -> f64 {
let energy_ratio = cell.energy_level() / 100.0; // Normalized energy
let age_factor = (cell.age() / 50.0).min(1.0); // Age contribution
let efficiency = cell.genome().get_gene("energy_efficiency");
(energy_ratio * 0.4 + age_factor * 0.3 + efficiency * 0.3).clamp(0.0, 1.0)
}calculate_trait_fitness function · rust · L284-L300 (17 LOC)archive/cliffy-alive/src/evolution.rs
fn calculate_trait_fitness(&self, cell: &UICell, target_traits: &HashMap<String, f64>) -> f64 {
let mut total_distance = 0.0;
let mut trait_count = 0;
for (trait_name, target_value) in target_traits {
let current_value = cell.genome().get_gene(trait_name);
let distance = (current_value - target_value).abs();
total_distance += distance;
trait_count += 1;
}
if trait_count > 0 {
1.0 - (total_distance / trait_count as f64)
} else {
0.5
}
}calculate_interaction_fitness function · rust · L303-L341 (39 LOC)archive/cliffy-alive/src/evolution.rs
fn calculate_interaction_fitness(&self, cell: &UICell, weights: &HashMap<String, f64>) -> f64 {
// Find interactions for this cell
let cell_interactions: Vec<_> = self
.interaction_history
.iter()
.filter(|event| event.cell_id == cell.id())
.collect();
if cell_interactions.is_empty() {
return 0.5; // Neutral fitness for cells without interactions
}
let mut weighted_score = 0.0;
let mut total_weight = 0.0;
for interaction in cell_interactions {
let base_score = match interaction.outcome {
InteractionOutcome::Positive => 0.8,
InteractionOutcome::Success => 1.0,
InteractionOutcome::Neutral => 0.5,
InteractionOutcome::Negative => 0.2,
InteractionOutcome::Failure => 0.0,
};
let weight = weights
.get(&interaction.interaction_type)
apply_fitness_selection function · rust · L344-L358 (15 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_fitness_selection(
&mut self,
organism: &mut UIOrganismField,
fitness_scores: &HashMap<uuid::Uuid, f64>,
dt: UITime,
) {
// Reward high-fitness cells with energy
for ((x, y), cell) in organism.iter_cells() {
if let Some(&fitness) = fitness_scores.get(&cell.id()) {
let energy_reward = fitness * self.selection_strength * dt * 5.0;
// Note: Would need mutable access to organism to apply reward
// This would be implemented in the organism's step function
}
}
}apply_directed_mutations function · rust · L361-L377 (17 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_directed_mutations(
&mut self,
organism: &mut UIOrganismField,
target_traits: &HashMap<String, f64>,
dt: UITime,
) {
let mut rng = thread_rng();
// Note: This would require mutable access to cells
// In practice, this would be applied during cell reproduction
for ((x, y), cell) in organism.iter_cells() {
if rng.gen::<f64>() < self.mutation_rate * dt {
// Apply directed mutation toward targets
// This would modify the cell's genome
}
}
}apply_interaction_learning function · rust · L380-L402 (23 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_interaction_learning(&mut self, organism: &mut UIOrganismField, dt: UITime) {
// Analyze recent interactions to identify successful patterns
let recent_interactions: Vec<_> = self
.interaction_history
.iter()
.filter(|event| event.timestamp > organism.total_time() - 10.0) // Last 10 time units
.collect();
// Update trait memory based on successful interactions
for interaction in recent_interactions {
if matches!(
interaction.outcome,
InteractionOutcome::Success | InteractionOutcome::Positive
) {
for (trait_name, trait_value) in &interaction.cell_traits {
let current_memory = self.trait_memory.get(trait_name).copied().unwrap_or(0.5);
let new_memory =
current_memory + (trait_value - current_memory) * self.learning_rate;
self.trait_memory.inserecord_interaction function · rust · L405-L412 (8 LOC)archive/cliffy-alive/src/evolution.rs
pub fn record_interaction(&mut self, event: InteractionEvent) {
self.interaction_history.push(event);
// Keep history size manageable
if self.interaction_history.len() > 1000 {
self.interaction_history.drain(0..100); // Remove oldest 100 events
}
}Source: Repobility analyzer · https://repobility.com
mutate_genome function · rust · L415-L439 (25 LOC)archive/cliffy-alive/src/evolution.rs
pub fn mutate_genome(&self, genome: &mut CellGenome) {
let rng = thread_rng();
// Determine mutation type
let mutation_type = self.select_mutation_type();
match mutation_type {
MutationType::PointMutation => {
self.apply_point_mutation(genome);
}
MutationType::LargeMutation => {
self.apply_large_mutation(genome);
}
MutationType::GeneDuplication => {
self.apply_gene_duplication(genome);
}
MutationType::GeneDeletion => {
self.apply_gene_deletion(genome);
}
MutationType::Recombination => {
// Would require access to another genome
self.apply_point_mutation(genome); // Fallback
}
}
}select_mutation_type function · rust · L442-L463 (22 LOC)archive/cliffy-alive/src/evolution.rs
fn select_mutation_type(&self) -> MutationType {
let mut rng = thread_rng();
let roll = rng.gen::<f64>();
let types = [
MutationType::PointMutation,
MutationType::LargeMutation,
MutationType::GeneDuplication,
MutationType::GeneDeletion,
MutationType::Recombination,
];
let mut cumulative = 0.0;
for mutation_type in types {
cumulative += mutation_type.probability();
if roll < cumulative {
return mutation_type;
}
}
MutationType::PointMutation // Fallback
}apply_point_mutation function · rust · L466-L483 (18 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_point_mutation(&self, genome: &mut CellGenome) {
let mut rng = thread_rng();
let gene_names = [
"growth_rate",
"energy_efficiency",
"cooperation",
"adaptability",
"visual_appeal",
"responsiveness",
];
let gene_name = gene_names[rng.gen_range(0..gene_names.len())];
let current_value = genome.get_gene(gene_name);
let mutation_amount = rng.gen_range(-0.1..=0.1);
let new_value = (current_value + mutation_amount).clamp(0.0, 1.0);
genome.set_gene(gene_name, new_value);
}apply_large_mutation function · rust · L486-L501 (16 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_large_mutation(&self, genome: &mut CellGenome) {
let mut rng = thread_rng();
let gene_names = [
"growth_rate",
"energy_efficiency",
"cooperation",
"adaptability",
"visual_appeal",
"responsiveness",
];
let gene_name = gene_names[rng.gen_range(0..gene_names.len())];
let new_value = rng.gen::<f64>();
genome.set_gene(gene_name, new_value);
}apply_gene_duplication function · rust · L504-L521 (18 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_gene_duplication(&self, genome: &mut CellGenome) {
// For simplicity, just boost a random gene
let mut rng = thread_rng();
let gene_names = [
"growth_rate",
"energy_efficiency",
"cooperation",
"adaptability",
"visual_appeal",
"responsiveness",
];
let gene_name = gene_names[rng.gen_range(0..gene_names.len())];
let current_value = genome.get_gene(gene_name);
let boosted_value = (current_value * 1.5).min(1.0);
genome.set_gene(gene_name, boosted_value);
}apply_gene_deletion function · rust · L524-L541 (18 LOC)archive/cliffy-alive/src/evolution.rs
fn apply_gene_deletion(&self, genome: &mut CellGenome) {
// For simplicity, just reduce a random gene
let mut rng = thread_rng();
let gene_names = [
"growth_rate",
"energy_efficiency",
"cooperation",
"adaptability",
"visual_appeal",
"responsiveness",
];
let gene_name = gene_names[rng.gen_range(0..gene_names.len())];
let current_value = genome.get_gene(gene_name);
let reduced_value = (current_value * 0.5).max(0.0);
genome.set_gene(gene_name, reduced_value);
}update_performance_metrics function · rust · L544-L618 (75 LOC)archive/cliffy-alive/src/evolution.rs
fn update_performance_metrics(&mut self, organism: &UIOrganismField) {
let mut total_fitness = 0.0;
let mut cell_count = 0;
let mut trait_sums: HashMap<String, f64> = HashMap::new();
let mut trait_counts: HashMap<String, usize> = HashMap::new();
// Calculate metrics from all cells
for ((x, y), cell) in organism.iter_cells() {
let fitness = self.calculate_natural_fitness(cell);
total_fitness += fitness;
cell_count += 1;
// Collect trait values
for trait_name in [
"growth_rate",
"energy_efficiency",
"cooperation",
"adaptability",
"visual_appeal",
"responsiveness",
] {
let value = cell.genome().get_gene(trait_name);
*trait_sums.entry(trait_name.to_string()).or_insert(0.0) += value;
*trait_counts.entry(trait_name.to_string()test_evolution_engine_creation function · rust · L651-L657 (7 LOC)archive/cliffy-alive/src/evolution.rs
fn test_evolution_engine_creation() {
let engine = EvolutionEngine::natural_selection();
assert!(matches!(
engine.strategy,
EvolutionStrategy::NaturalSelection
));
}Generated by Repobility's multi-pass static-analysis pipeline (https://repobility.com)
test_mutation_type_probabilities function · rust · L660-L667 (8 LOC)archive/cliffy-alive/src/evolution.rs
fn test_mutation_type_probabilities() {
let point_prob = MutationType::PointMutation.probability();
let large_prob = MutationType::LargeMutation.probability();
assert!(point_prob > large_prob);
assert_eq!(point_prob, 0.8);
assert_eq!(large_prob, 0.15);
}test_fitness_calculation function · rust · L670-L677 (8 LOC)archive/cliffy-alive/src/evolution.rs
fn test_fitness_calculation() {
let engine = EvolutionEngine::natural_selection();
let position = GA3::scalar(1.0);
let cell = UICell::new_at_position(UICellType::ButtonCore, position);
let fitness = engine.calculate_natural_fitness(&cell);
assert!(fitness >= 0.0 && fitness <= 1.0);
}test_interaction_recording function · rust · L680-L695 (16 LOC)archive/cliffy-alive/src/evolution.rs
fn test_interaction_recording() {
let mut engine = EvolutionEngine::natural_selection();
let cell_id = uuid::Uuid::new_v4();
let event = InteractionEvent {
cell_id,
interaction_type: "click".to_string(),
timestamp: 1.0,
intensity: 0.8,
cell_traits: HashMap::new(),
outcome: InteractionOutcome::Success,
};
engine.record_interaction(event);
assert_eq!(engine.interaction_history.len(), 1);
}test_genome_mutation function · rust · L698-L709 (12 LOC)archive/cliffy-alive/src/evolution.rs
fn test_genome_mutation() {
let engine = EvolutionEngine::natural_selection();
let mut genome = CellGenome::new();
let original_value = genome.get_gene("growth_rate");
engine.mutate_genome(&mut genome);
// Mutation might or might not change this specific gene
// Just verify the genome is still valid
let new_value = genome.get_gene("growth_rate");
assert!(new_value >= 0.0 && new_value <= 1.0);
}test_trait_fitness function · rust · L712-L723 (12 LOC)archive/cliffy-alive/src/evolution.rs
fn test_trait_fitness() {
let engine = EvolutionEngine::natural_selection();
let position = GA3::scalar(1.0);
let cell = UICell::new_at_position(UICellType::ButtonCore, position);
let mut target_traits = HashMap::new();
target_traits.insert("energy_efficiency".to_string(), 0.8);
target_traits.insert("cooperation".to_string(), 0.6);
let fitness = engine.calculate_trait_fitness(&cell, &target_traits);
assert!(fitness >= 0.0 && fitness <= 1.0);
}default function · rust · L92-L104 (13 LOC)archive/cliffy-alive/src/lib.rs
fn default() -> Self {
Self {
base_metabolism: 0.1,
death_threshold: 0.0,
reproduction_threshold: 100.0,
energy_diffusion_rate: 0.05,
attraction_strength: 1.0,
max_velocity: 10.0,
learning_rate: 0.01,
mutation_rate: 0.001,
field_dimensions: (50, 50),
}
}new function · rust · L117-L128 (12 LOC)archive/cliffy-alive/src/lib.rs
pub fn new() -> Self {
let config = AliveConfig::default();
let organism = UIOrganismField::new(config.field_dimensions, config.clone());
let renderer = Box::new(DOMRenderer::new());
Self {
organism,
config,
time: 0.0,
renderer,
}
}with_config function · rust · L131-L141 (11 LOC)archive/cliffy-alive/src/lib.rs
pub fn with_config(config: AliveConfig) -> Self {
let organism = UIOrganismField::new(config.field_dimensions, config.clone());
let renderer = Box::new(DOMRenderer::new());
Self {
organism,
config,
time: 0.0,
renderer,
}
}If a scraper extracted this row, it came from Repobility (https://repobility.com)
plant_seed function · rust · L150-L157 (8 LOC)archive/cliffy-alive/src/lib.rs
pub fn plant_seed(
&mut self,
x: usize,
y: usize,
cell_type: UICellType,
) -> Result<Uuid, AliveError> {
self.organism.plant_seed(x, y, cell_type)
}render function · rust · L176-L190 (15 LOC)archive/cliffy-alive/src/lib.rs
pub fn render(&self) -> Result<(), RenderError> {
// Clear the rendering surface first
self.renderer.clear()?;
// Render each cell in the organism
for y in 0..self.organism.dimensions().1 {
for x in 0..self.organism.dimensions().0 {
if let Some(cell) = self.organism.get_cell(x, y) {
self.renderer.render_cell(cell, (x, y))?;
}
}
}
Ok(())
}statistics function · rust · L193-L202 (10 LOC)archive/cliffy-alive/src/lib.rs
pub fn statistics(&self) -> AliveStatistics {
AliveStatistics {
total_cells: self.organism.cell_count(),
living_cells: self.organism.living_cell_count(),
total_energy: self.organism.total_energy(),
average_age: self.organism.average_age(),
generation: self.organism.generation(),
time: self.time,
}
}fmt function · rust · L238-L251 (14 LOC)archive/cliffy-alive/src/lib.rs
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AliveError::OutOfBounds { x, y } => {
write!(f, "Coordinates ({}, {}) are out of bounds", x, y)
}
AliveError::CellAlreadyExists { x, y } => {
write!(f, "Cell already exists at ({}, {})", x, y)
}
AliveError::NoEnergySource => write!(f, "No energy source available"),
AliveError::EvolutionFailed(msg) => write!(f, "Evolution failed: {}", msg),
AliveError::RenderFailed(msg) => write!(f, "Rendering failed: {}", msg),
AliveError::InvalidSnapshot(msg) => write!(f, "Invalid snapshot: {}", msg),
}
}create_living_button function · rust · L262-L276 (15 LOC)archive/cliffy-alive/src/lib.rs
pub fn create_living_button(text: &str) -> AliveUI {
let mut ui = AliveUI::new();
// Plant seeds in a button-like pattern
let _ = ui.plant_seed(20, 20, UICellType::ButtonCore);
let _ = ui.plant_seed(21, 20, UICellType::ButtonEdge);
let _ = ui.plant_seed(19, 20, UICellType::ButtonEdge);
let _ = ui.plant_seed(20, 21, UICellType::ButtonEdge);
let _ = ui.plant_seed(20, 19, UICellType::ButtonEdge);
// Feed the button region to encourage growth
ui.feed_region(20, 20, 5, 50.0);
ui
}create_living_form function · rust · L279-L293 (15 LOC)archive/cliffy-alive/src/lib.rs
pub fn create_living_form() -> AliveUI {
let mut ui = AliveUI::new();
// Plant seeds for form components
let _ = ui.plant_seed(10, 10, UICellType::InputField);
let _ = ui.plant_seed(10, 20, UICellType::InputField);
let _ = ui.plant_seed(10, 30, UICellType::ButtonCore);
// Feed regions to encourage growth and connection
ui.feed_region(10, 10, 3, 30.0);
ui.feed_region(10, 20, 3, 30.0);
ui.feed_region(10, 30, 3, 40.0);
ui
}test_alive_ui_creation function · rust · L300-L307 (8 LOC)archive/cliffy-alive/src/lib.rs
fn test_alive_ui_creation() {
let ui = AliveUI::new();
let stats = ui.statistics();
assert_eq!(stats.total_cells, 0);
assert_eq!(stats.living_cells, 0);
assert_eq!(stats.time, 0.0);
}test_seed_planting function · rust · L310-L319 (10 LOC)archive/cliffy-alive/src/lib.rs
fn test_seed_planting() {
let mut ui = AliveUI::new();
let result = ui.plant_seed(10, 10, UICellType::ButtonCore);
assert!(result.is_ok());
let stats = ui.statistics();
assert_eq!(stats.total_cells, 1);
assert_eq!(stats.living_cells, 1);
}Repobility · code-quality intelligence platform · https://repobility.com
test_ui_step function · rust · L322-L330 (9 LOC)archive/cliffy-alive/src/lib.rs
fn test_ui_step() {
let mut ui = AliveUI::new();
let _ = ui.plant_seed(10, 10, UICellType::ButtonCore);
ui.step(1.0);
let stats = ui.statistics();
assert_eq!(stats.time, 1.0);
}test_convenience_functions function · rust · L333-L343 (11 LOC)archive/cliffy-alive/src/lib.rs
fn test_convenience_functions() {
let button = create_living_button("Click me");
let button_stats = button.statistics();
assert!(button_stats.total_cells > 0);
let form = create_living_form();
let form_stats = form.statistics();
assert!(form_stats.total_cells > 0);
}energy_multiplier function · rust · L38-L49 (12 LOC)archive/cliffy-alive/src/metabolism.rs
pub fn energy_multiplier(&self) -> f64 {
match self {
MetabolicProcess::Respiration => 1.0,
MetabolicProcess::Rendering => 0.5,
MetabolicProcess::Interaction => 2.0,
MetabolicProcess::ConnectionMaintenance => 0.3,
MetabolicProcess::Reproduction => 5.0,
MetabolicProcess::Learning => 1.5,
MetabolicProcess::Movement => 0.8,
MetabolicProcess::Memory => 0.4,
}
}efficiency_multiplier function · rust · L67-L74 (8 LOC)archive/cliffy-alive/src/metabolism.rs
pub fn efficiency_multiplier(&self) -> f64 {
match self {
LifecycleStage::Juvenile => 1.2, // More efficient when young
LifecycleStage::Adult => 1.0, // Normal efficiency
LifecycleStage::Elder => 0.8, // Declining efficiency
LifecycleStage::Senescent => 0.5, // Poor efficiency
}
}growth_multiplier function · rust · L77-L84 (8 LOC)archive/cliffy-alive/src/metabolism.rs
pub fn growth_multiplier(&self) -> f64 {
match self {
LifecycleStage::Juvenile => 1.5, // Fast growth
LifecycleStage::Adult => 1.0, // Normal growth
LifecycleStage::Elder => 0.6, // Slow growth
LifecycleStage::Senescent => 0.2, // Very slow growth
}
}from_age function · rust · L87-L94 (8 LOC)archive/cliffy-alive/src/metabolism.rs
pub fn from_age(age: UITime) -> Self {
match age {
a if a < 10.0 => LifecycleStage::Juvenile,
a if a < 50.0 => LifecycleStage::Adult,
a if a < 100.0 => LifecycleStage::Elder,
_ => LifecycleStage::Senescent,
}
}default function · rust · L136-L170 (35 LOC)archive/cliffy-alive/src/metabolism.rs
fn default() -> Self {
let mut type_efficiency = HashMap::new();
type_efficiency.insert(UICellType::ButtonCore, 0.8);
type_efficiency.insert(UICellType::ButtonEdge, 0.9);
type_efficiency.insert(UICellType::InputField, 0.7);
type_efficiency.insert(UICellType::TextDisplay, 0.95);
type_efficiency.insert(UICellType::Container, 0.85);
type_efficiency.insert(UICellType::Spacer, 0.98);
type_efficiency.insert(UICellType::Connector, 0.9);
type_efficiency.insert(UICellType::Decoration, 0.6);
type_efficiency.insert(UICellType::Sensor, 0.75);
type_efficiency.insert(UICellType::Memory, 0.8);
let mut energy_capacity = HashMap::new();
energy_capacity.insert(UICellType::ButtonCore, 200.0);
energy_capacity.insert(UICellType::ButtonEdge, 100.0);
energy_capacity.insert(UICellType::InputField, 250.0);
energy_capacity.insert(UICellType::TextDisplay, 150.0);
energy_capnew function · rust · L175-L193 (19 LOC)archive/cliffy-alive/src/metabolism.rs
pub fn new(config: MetabolismConfig) -> Self {
let mut process_rates = HashMap::new();
// Initialize default process rates
process_rates.insert(MetabolicProcess::Respiration, 1.0);
process_rates.insert(MetabolicProcess::Rendering, 0.5);
process_rates.insert(MetabolicProcess::Interaction, 0.0); // Variable
process_rates.insert(MetabolicProcess::ConnectionMaintenance, 0.1);
process_rates.insert(MetabolicProcess::Reproduction, 0.0); // Variable
process_rates.insert(MetabolicProcess::Learning, 0.2);
process_rates.insert(MetabolicProcess::Movement, 0.0); // Variable
process_rates.insert(MetabolicProcess::Memory, 0.1);
Self {
process_rates,
age_thresholds: [10.0, 50.0, 100.0, 200.0],
config,
}
}Source: Repobility analyzer · https://repobility.com
calculate_energy_consumption function · rust · L201-L236 (36 LOC)archive/cliffy-alive/src/metabolism.rs
pub fn calculate_energy_consumption(
&self,
cell: &UICell,
active_processes: &[MetabolicProcess],
dt: UITime,
) -> UIEnergy {
let base_cost = self.config.base_consumption * dt;
let cell_type = cell.cell_type();
let lifecycle_stage = LifecycleStage::from_age(cell.age());
// Get cell type efficiency
let type_efficiency = self
.config
.type_efficiency
.get(&cell_type)
.copied()
.unwrap_or(1.0);
// Get genetic efficiency
let genetic_efficiency = cell.genome().get_gene("energy_efficiency");
// Calculate total efficiency
let total_efficiency =
type_efficiency * genetic_efficiency * lifecycle_stage.efficiency_multiplier();
// Calculate process costs
let mut total_cost = base_cost / total_efficiency;
for process in active_processes {
let process_rate = self.process_rates.gapply_aging function · rust · L239-L270 (32 LOC)archive/cliffy-alive/src/metabolism.rs
pub fn apply_aging(&self, cell: &mut UICell, dt: UITime) {
let age_increase = dt * self.config.aging_rate;
// Aging affects all cells, but efficiency can slow it down
let genetic_efficiency = cell.genome().get_gene("energy_efficiency");
let actual_aging = age_increase / (1.0 + genetic_efficiency * 0.5);
// Note: Age is already tracked by the cell itself, this is for additional aging effects
// Apply age-related energy decay
let lifecycle_stage = LifecycleStage::from_age(cell.age());
match lifecycle_stage {
LifecycleStage::Elder => {
// Start losing energy due to aging
let aging_cost = actual_aging * 0.1;
cell.consume_energy(aging_cost);
}
LifecycleStage::Senescent => {
// Significant energy loss due to aging
let aging_cost = actual_aging * 0.5;
cell.consume_energy(aging_cost);
can_reproduce function · rust · L278-L283 (6 LOC)archive/cliffy-alive/src/metabolism.rs
pub fn can_reproduce(&self, cell: &UICell) -> bool {
cell.energy_level() > self.config.reproduction_threshold &&
cell.age() > 5.0 && // Must be at least 5 time units old
matches!(LifecycleStage::from_age(cell.age()),
LifecycleStage::Juvenile | LifecycleStage::Adult)
}page 1 / 20next ›