Production-grade Evolutionary AI.
- Inputs:
get_evo_inputs()must return normalized floats (approx 0.0 to 1.0). - Lifecycle: Evolution runs on
EvoManager.end_wave(). Genes inherit on spawn (_ready).
Attach this to a CharacterBody3D. It uses safe references and triggers evolution automatically.
extends CharacterBody3D
var brain: EvoBrain # Reference to avoid string-path errors
func _ready():
# 1. Create Brain
brain = EvoBrain.new()
brain.species_id = "demo_bot"
add_child(brain)
# 2. Listen to decisions
brain.action_selected.connect(_on_action)
# 3. Simulate Wave End (for testing)
get_tree().create_timer(10.0).timeout.connect(func():
EvoManager.end_wave()
print(">> WAVE ENDED. Genes Saved.")
get_tree().reload_current_scene()
)
# 4. Provide Senses
func get_evo_inputs() -> Array[float]:
# Visible, Distance, Health, Ammo
return [1.0, 0.5, 1.0, 1.0]
# 5. Act & Reward
func _on_action(action_id: int):
var moves = ["PATROL", "CHASE", "FLANK_L", "FLANK_R", "PEEK", "SHOOT", "RETREAT", "RELOAD"]
print("Action: ", moves[action_id])
if action_id == 5: # Shoot
# Use variable reference, not $NodePath
brain.reward_action(1.0)