import random import time import threading class NAND: def __init__(self, name): self.name = name self.inputs = [None, None] self.output = None def connect(self, other): available_inputs = [i for i, x in enumerate(self.inputs) if x is None] if available_inputs: self.inputs[random.choice(available_inputs)] = other other.output = self self.update_output() def disconnect(self): if self.inputs[0] is not None: self.inputs[0].output = None if self.inputs[1] is not None: self.inputs[1].output = None self.inputs = [None, None] def update_output(self): if all([i is not None for i in self.inputs]): self.output = 0 if all([i.output == 1 for i in self.inputs]) else 1 def random_operation(gates, freq, input_freq): while True: for _ in range(freq): gate1 = random.choice(gates) gate2 = random.choice(gates) if gate1 is not gate2 and random.choice([True, False]): gate1.connect(gate2) else: gate1.disconnect() for _ in range(input_freq): gate = random.choice(gates) if gate.inputs[0] is None: gate.inputs[0] = random.choice([0, 1]) if gate.inputs[1] is None: gate.inputs[1] = random.choice([0, 1]) gate.update_output() time.sleep(1) def main(): n_gates = int(input("Enter the number of NAND gates: ")) freq = int(input("Enter the frequency of random connections/disconnections per second: ")) input_freq = int(input("Enter the frequency of random inputs per second: ")) gates = [NAND(i) for i in range(n_gates)] game_thread = threading.Thread(target=random_operation, args=(gates, freq, input_freq)) game_thread.start() print("Game started. Type 'stop' to stop the game.") while True: command = input() if command.lower() == 'stop': game_thread.join() print("Game stopped.") break if __name__ == "__main__": main()




NAND게이트는 만능게이트니까 모든논리를 만들수 있잖음


그래서 그 NAND게이트를 일정시간동안 수정가능한 빈도로 랜덤하게 연결, 연결제거를 수행해서


랜덤한 논리를 나타나게함


그리고 NAND게이트중에 아무 입력도 연결되어있지않은 NAND게이트의 입력을 랜덤으로 바꾸는데, 그 바꾸는것의 빈도도 조절할수있음



이렇게 해서 얻고자 하는게 무엇이냐면


랜덤한 논리를 만들고, 상호작용시켜서, 적자생존이 일어나고


그 적자생존에서 뭔가가 탄생하기를 바라는것임