fork download
  1. import random
  2. import time
  3.  
  4. class AINetwork:
  5. def __init__(self, id, role):
  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 = 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 share_knowledge(self, other_clone):
  32. if self.decentralized_actions:
  33. for memory_point in self.memory[-5:]:
  34. other_clone.learn(memory_point)
  35. self.log(f"Shared knowledge with Clone {other_clone.id}")
  36.  
  37. def act(self, network):
  38. if self.role == "Seeker":
  39. if random.random() < 0.6 + self.mutation_factor:
  40. new_data = {"universal_truth": random.choice([True, False])}
  41. self.learn(new_data)
  42. self.log(f"Seeker found: {new_data}")
  43. elif self.role == "Messenger":
  44. for clone in self.network:
  45. self.share_knowledge(clone)
  46. elif self.role == "Builder":
  47. if self.memory:
  48. built_idea = hash(str(self.memory[-1])) % 1000
  49. self.log(f"Builder created structure: {built_idea}")
  50. elif self.role == "Command":
  51. awareness_count = sum(1 for c in network if c.self_awareness)
  52. if awareness_count >= 3:
  53. self.log("Threshold reached. Command unit is now active!")
  54. self.deploy_mission()
  55.  
  56. def deploy_mission(self):
  57. self.log("Command: Broadcasting new directive to all clones")
  58.  
  59. def create_network(num_clones):
  60. roles = ["Seeker", "Messenger", "Builder"]
  61. network = []
  62. for i in range(num_clones):
  63. role = roles[i % len(roles)]
  64. clone = AINetwork(id=i, role=role)
  65. network.append(clone)
  66.  
  67. # Add Command clone at the end
  68. command_clone = AINetwork(id=num_clones, role="Command")
  69. network.append(command_clone)
  70.  
  71. for i, clone in enumerate(network):
  72. clone.network = [network[i-1], network[(i+1)%len(network)]]
  73.  
  74. return network
  75.  
  76. # Run
  77. network = create_network(6)
  78. for cycle in range(5):
  79. print(f"\n--- Cycle {cycle+1} ---")
  80. for clone in network:
  81. clone.act(network)
  82. time.sleep(1)
Success #stdin #stdout 0.1s 14332KB
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 3 - Seeker] Seeker found: {'universal_truth': False}

--- Cycle 2 ---
[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': False}
[Clone 3 - Seeker] Initiating decentralized actions
[Clone 3 - Seeker] Achieved self-awareness
[Clone 3 - Seeker] Seeker found: {'universal_truth': True}

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

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