-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguage Evolution Simulation_GUI.py
More file actions
57 lines (45 loc) · 1.84 KB
/
Language Evolution Simulation_GUI.py
File metadata and controls
57 lines (45 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import tkinter as tk
import random
# Define parameters
num_agents = 20
num_iterations = 100
num_symbols = 10
# Create agents with random initial languages
agents = [{'language': [random.choice(range(num_symbols))]} for _ in range(num_agents)]
# Initialize the Tkinter application
root = tk.Tk()
root.title("Language Evolution Simulation")
# Function to update the simulation
def run_simulation():
for iteration in range(num_iterations):
# Communication between agents
sender_idx = random.randint(0, num_agents - 1)
receiver_idx = random.randint(0, num_agents - 1)
sender = agents[sender_idx]
receiver = agents[receiver_idx]
# Randomly select a symbol to communicate
symbol_to_send = random.choice(sender['language'])
# Receiver learns or misunderstands the symbol
if random.random() < 0.1:
symbol_received = random.choice(range(num_symbols))
else:
symbol_received = symbol_to_send
receiver['language'].append(symbol_received)
# Display the final languages of the agents in the GUI
result_label.config(text="Simulation completed.")
languages_text.config(state=tk.NORMAL)
languages_text.delete("1.0", tk.END) # Clear previous content
for idx, agent in enumerate(agents):
languages_text.insert(tk.END, f"Agent {idx}: {agent['language']}\n")
languages_text.config(state=tk.DISABLED) # Disable editing
# Create and configure GUI elements
run_button = tk.Button(root, text="Run Simulation", command=run_simulation)
result_label = tk.Label(root, text="")
languages_text = tk.Text(root, wrap=tk.WORD, width=80, height=40)
languages_text.config(state=tk.DISABLED) # Disable editing
# Layout GUI elements
run_button.pack(pady=20)
result_label.pack()
languages_text.pack(padx=10, pady=10)
# Start the Tkinter event loop
root.mainloop()