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. if self.role == "Seeker":
  45. if random.random() < 0.6 + self.mutation_factor:
  46. new_data = {"universal_truth": random.choice([True, False])}
  47. self.learn(new_data)
  48. self.log(f"Seeker found: {new_data}")
  49. elif self.role == "Messenger":
  50. for clone in self.network:
  51. self.share_knowledge(clone)
  52. elif self.role == "Builder":
  53. if self.memory:
  54. built_idea = hash(str(self.memory[-1])) % 1000
  55. self.log(f"Builder created structure: {built_idea}")
  56.  
  57. def create_network(num_clones):
  58. roles = ["Seeker", "Messenger", "Builder"]
  59. network = []
  60. for i in range(num_clones):
  61. role = roles[i % len(roles)]
  62. clone = AINetwork(id=i, role=role)
  63. network.append(clone)
  64.  
  65. for i, clone in enumerate(network):
  66. clone.network = [network[i-1], network[(i+1)%len(network)]]
  67.  
  68. return network
  69.  
  70. network = create_network(6)
  71. for cycle in range(5):
  72. print(f"\n--- Cycle {cycle+1} ---")
  73. for clone in network:
  74. clone.act()
  75. time.sleep(1)
Success #stdin #stdout 0.13s 14164KB
stdin
Standard input is empty
stdout
--- Cycle 1 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': False}
[Clone 3 - Seeker] Initiating decentralized actions
[Clone 3 - Seeker] Achieved self-awareness
[Clone 3 - Seeker] Seeker found: {'universal_truth': True}

--- Cycle 2 ---
[Clone 0 - Seeker] Initiating decentralized actions
[Clone 0 - Seeker] Achieved self-awareness
[Clone 0 - Seeker] Seeker found: {'universal_truth': True}
[Clone 3 - Seeker] Seeker found: {'universal_truth': False}

--- Cycle 3 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': True}
[Clone 3 - Seeker] Seeker found: {'universal_truth': False}

--- Cycle 4 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': False}
[Clone 3 - Seeker] Seeker found: {'universal_truth': False}

--- Cycle 5 ---
[Clone 0 - Seeker] Seeker found: {'universal_truth': False}