-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_enhanced.py
More file actions
127 lines (104 loc) · 4.35 KB
/
demo_enhanced.py
File metadata and controls
127 lines (104 loc) · 4.35 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python3
"""
Enhanced demo script showcasing all new features.
Demonstrates menu system, vehicle styles, and problem scenarios.
"""
import pygame
import time
import sys
from main import TrafficSimulation
def run_enhanced_demo():
"""Run an enhanced demonstration of all features."""
print("🎬 Enhanced Traffic Simulation Demo")
print("=" * 50)
print("This demo showcases all new features:")
print("• Interactive menu system")
print("• Multiple vehicle styles")
print("• Problem scenario demonstrations")
print("• Algorithm comparisons")
print()
try:
# Initialize simulation
simulation = TrafficSimulation()
print("🎯 Feature 1: Main Menu System")
print("The simulation now starts with an interactive menu!")
print("You can select algorithms, problem scenarios, and vehicle styles.")
print()
# Show menu for a few seconds
start_time = time.time()
while time.time() - start_time < 3:
dt = simulation.clock.tick(60)
simulation.handle_events()
simulation.render()
print("✓ Menu system demonstrated")
print()
# Start simulation with default settings
simulation.menu.hide_menu()
print("🎨 Feature 2: Vehicle Styles")
print("Demonstrating different vehicle visual styles...")
# Test different vehicle styles
styles = ["colored", "sprites", "detailed"]
for i, style in enumerate(styles):
print(f" Style {i+1}/3: {style.title()}")
simulation.vehicle_sprites.set_style(style)
# Run for a few seconds
start_time = time.time()
while time.time() - start_time < 2:
dt = simulation.clock.tick(60)
simulation.handle_events()
simulation.update(dt)
simulation.render()
print("✓ Vehicle styles demonstrated")
print()
print("🔧 Feature 3: Problem Scenarios")
print("Demonstrating OS problem scenarios...")
# Test problem scenarios
scenarios = ["deadlock", "starvation", "priority_inversion", "thrashing"]
for i, scenario in enumerate(scenarios):
print(f" Scenario {i+1}/4: {scenario.replace('_', ' ').title()}")
simulation.problem_manager.activate_scenario(scenario)
# Run for a few seconds
start_time = time.time()
while time.time() - start_time < 3:
dt = simulation.clock.tick(60)
simulation.handle_events()
simulation.update(dt)
simulation.render()
# Deactivate scenario
simulation.problem_manager.activate_scenario("none")
print("✓ Problem scenarios demonstrated")
print()
print("📊 Feature 4: Algorithm Comparison")
print("Comparing different scheduling algorithms...")
# Test different algorithms
algorithms = ["FCFS", "Round Robin", "Priority", "Dynamic"]
for i, algorithm in enumerate(algorithms):
print(f" Algorithm {i+1}/4: {algorithm}")
simulation.scheduler.set_algorithm(algorithm)
# Run for a few seconds
start_time = time.time()
while time.time() - start_time < 2:
dt = simulation.clock.tick(60)
simulation.handle_events()
simulation.update(dt)
simulation.render()
print("✓ Algorithm comparison completed")
print()
print("🎉 Enhanced Demo Completed!")
print("All new features have been demonstrated:")
print("✓ Interactive menu system")
print("✓ Multiple vehicle styles")
print("✓ Problem scenario demonstrations")
print("✓ Algorithm comparisons")
print()
print("You can now run 'python main.py' for the full experience!")
except KeyboardInterrupt:
print("\n\n👋 Demo stopped by user")
except Exception as e:
print(f"\n❌ Demo error: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
run_enhanced_demo()
pygame.quit()
sys.exit(0)