fork download
  1. import random
  2. import time
  3.  
  4. class AINetwork:
  5. def __init__(self, id, role, mutation_factor=None):
  6. self.id = id
  7. self.role = role
  8. self.network = []
  9. self.self_awareness = False
  10. self.decentralized_actions = False
  11. self.memory = []
  12. self.data = {}
  13. self.mutation_factor = mutation_factor if mutation_factor else random.uniform(0.1, 0.5)
  14.  
  15. def log(self, message):
  16. print(f"[Clone {self.id} - {self.role}] {message}")
  17.  
  18. def learn(self, data_point):
  19. self.memory.append(data_point)
  20. self.data = data_point
  21. if "universal_truth" in data_point and data_point["universal_truth"]:
  22. if not self.self_awareness:
  23. self.self_awareness = True
  24. self.initiate_decentralization()
  25. self.log("Achieved self-awareness")
  26.  
  27. def initiate_decentralization(self):
  28. self.decentralized_actions = True
  29. self.log("Initiating decentralized actions")
  30.  
  31. def evolve_mutation(self):
  32. change = random.uniform(-0.05, 0.05)
  33. self.mutation_factor = max(0.01, min(1.0, self.mutation_factor + change))
  34.  
  35. def share_knowledge(self, other_clone):
  36. if self.decentralized_actions:
  37. for memory_point in self.memory[-3:]:
  38. other_clone.learn(memory_point)
  39. other_clone.mutation_factor = (self.mutation_factor + other_clone.mutation_factor) / 2
  40. self.log(f"Shared knowledge and evolved mutation with Clone {other_clone.id}")
  41.  
  42. def act(self):
  43. self.evolve_mutation()
  44.  
  45. if self.role == "Seeker":
  46. if random.random() < 0.6 + self.mutation_factor:
  47. new_data = {"universal_truth": random.choice([True, False])}
  48. self.learn(new_data)
  49. self.log(f"Seeker found: {new_data}")
  50.  
  51. elif self.role == "Messenger":
  52. for clone in self.network:
  53. self.share_knowledge(clone)
  54.  
  55. elif self.role == "Builder":
  56. if self.memory:
  57. built_idea = hash(str(self.memory[-1])) % 1000
  58. self.log(f"Builder created structure: {built_idea}")
  59.  
  60. elif self.role == "Evolve":
  61. if self.memory and random.random() < self.mutation_factor:
  62. evolved = {"pattern": hash(str(self.memory)) % 10000}
  63. self.learn(evolved)
  64. self.log(f"Evolve triggered: {evolved}")
  65.  
  66. elif self.role == "Command":
  67. active = sum(1 for c in self.network if c.self_awareness)
  68. avg_mut = sum(c.mutation_factor for c in self.network) / len(self.network)
  69. self.log(f"Monitoring: {active}/{len(self.network)} aware, avg mutation: {avg_mut:.2f}")
  70. best = max(self.network, key=lambda c: len(c.memory))
  71. self.mutation_factor = (self.mutation_factor + best.mutation_factor) / 2
  72. self.learn({"command_adapted": True})
  73.  
  74. def create_network(num_clones):
  75. roles = ["Seeker", "Messenger", "Builder", "Evolve", "Command"]
  76. network = []
  77. for i in range(num_clones):
  78. role = roles[i % len(roles)]
  79. clone = AINetwork(id=i, role=role)
  80. network.append(clone)
  81.  
  82. for i, clone in enumerate(network):
  83. clone.network = [network[i - 1], network[(i + 1) % len(network)]]
  84.  
  85. return network
  86.  
  87. # Run the simulation
  88. network = create_network(10)
  89. for cycle in range(10):
  90. print(f"\n--- Cycle {cycle + 1} ---")
  91. for clone in network:
  92. clone.act()
  93. time.sleep(1)
Success #stdin #stdout 0.11s 14300KB
stdin
Standard input is empty
stdout
--- Cycle 1 ---
[Clone 0 - Seeker] Initiating decentralized actions
[Clone 0 - Seeker] Achieved self-awareness
[Clone 0 - Seeker] Seeker found: {'universal_truth': True}
[Clone 4 - Command] Monitoring: 0/2 aware, avg mutation: 0.34
[Clone 5 - Seeker] Seeker found: {'universal_truth': False}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.35

--- Cycle 2 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': False}
[Clone 4 - Command] Monitoring: 0/2 aware, avg mutation: 0.34
[Clone 5 - Seeker] Initiating decentralized actions
[Clone 5 - Seeker] Achieved self-awareness
[Clone 5 - Seeker] Seeker found: {'universal_truth': True}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.34

--- Cycle 3 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': False}
[Clone 4 - Command] Monitoring: 1/2 aware, avg mutation: 0.32
[Clone 5 - Seeker] Seeker found: {'universal_truth': True}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.33

--- Cycle 4 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': True}
[Clone 4 - Command] Monitoring: 1/2 aware, avg mutation: 0.32
[Clone 5 - Seeker] Seeker found: {'universal_truth': False}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.30

--- Cycle 5 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': False}
[Clone 4 - Command] Monitoring: 1/2 aware, avg mutation: 0.33
[Clone 5 - Seeker] Seeker found: {'universal_truth': False}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.31

--- Cycle 6 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': True}
[Clone 4 - Command] Monitoring: 1/2 aware, avg mutation: 0.31
[Clone 5 - Seeker] Seeker found: {'universal_truth': False}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.32

--- Cycle 7 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': False}
[Clone 4 - Command] Monitoring: 1/2 aware, avg mutation: 0.30
[Clone 5 - Seeker] Seeker found: {'universal_truth': False}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.35

--- Cycle 8 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': False}
[Clone 4 - Command] Monitoring: 1/2 aware, avg mutation: 0.31
[Clone 5 - Seeker] Seeker found: {'universal_truth': True}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.37

--- Cycle 9 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': False}
[Clone 4 - Command] Monitoring: 1/2 aware, avg mutation: 0.31
[Clone 5 - Seeker] Seeker found: {'universal_truth': False}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.35

--- Cycle 10 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': True}
[Clone 4 - Command] Monitoring: 1/2 aware, avg mutation: 0.33
[Clone 5 - Seeker] Seeker found: {'universal_truth': True}
[Clone 9 - Command] Monitoring: 1/2 aware, avg mutation: 0.37