15
15
"""
16
16
17
17
import numpy as np
18
- import matplotlib .pyplot as plt
19
18
from matplotlib import animation
19
+ import matplotlib .pyplot as plt
20
20
from matplotlib .colors import ListedColormap
21
21
22
22
@@ -571,7 +571,7 @@ def run_interactive_simulation(
571
571
# Helper demo functions
572
572
# -------------------------------------------------------------------------
573
573
574
- def demo_game_of_life ():
574
+ def demo_game_of_life () -> None :
575
575
"""Example 1: Conway's Game of Life (B3/S23)."""
576
576
try :
577
577
visualize_cellular_automaton (
@@ -585,7 +585,7 @@ def demo_game_of_life():
585
585
print (f"Error in Game of Life demo: { e } " )
586
586
587
587
588
- def demo_highlife ():
588
+ def demo_highlife () -> None :
589
589
"""Example 2: HighLife (B36/S23)."""
590
590
try :
591
591
visualize_cellular_automaton (
@@ -599,7 +599,7 @@ def demo_highlife():
599
599
print (f"Error in HighLife demo: { e } " )
600
600
601
601
602
- def demo_oscillator ():
602
+ def demo_oscillator () -> None :
603
603
"""Example 3: Oscillator (blinker)."""
604
604
try :
605
605
initial_state = np .zeros ((10 , 10 ), dtype = int )
@@ -615,7 +615,7 @@ def demo_oscillator():
615
615
print (f"Error in Oscillator demo: { e } " )
616
616
617
617
618
- def demo_randomized ():
618
+ def demo_randomized () -> None :
619
619
"""Example 4: Randomized automaton (B2/S23)."""
620
620
try :
621
621
visualize_cellular_automaton (
@@ -629,10 +629,10 @@ def demo_randomized():
629
629
print (f"Error in Randomized demo: { e } " )
630
630
631
631
632
- def demo_statistics ():
632
+ def demo_statistics () -> None :
633
633
"""Example 5: Print statistics about automaton evolution."""
634
634
try :
635
- final_state = run_cellular_automaton (
635
+ final_state = simulate_cellular_automaton (
636
636
rule_b = [3 ],
637
637
rule_s = [2 , 3 ],
638
638
size = 50 ,
@@ -641,9 +641,10 @@ def demo_statistics():
641
641
)
642
642
alive_counts = [np .sum (state ) for state in final_state ]
643
643
density = [count / (50 * 50 ) * 100 for count in alive_counts ]
644
+ average_population = f"{ np .mean (alive_counts ):.1f} cells"
644
645
645
646
print ("Statistics Example:" )
646
- print (f"-Average population: { np . mean ( alive_counts ):.1f } cells " )
647
+ print (f"-Average population: { average_population } " )
647
648
print (f"-Average density: { np .mean (density ):.1f} %" )
648
649
print (f"-Max population: { np .max (alive_counts )} " )
649
650
print (f"-Min population: { np .min (alive_counts )} " )
@@ -655,7 +656,7 @@ def demo_statistics():
655
656
# Main demo orchestrator
656
657
# -------------------------------------------------------------------------
657
658
658
- def demonstrate_cellular_automaton_features ():
659
+ def demonstrate_cellular_automaton_features () -> None :
659
660
"""Runs a set of cellular automaton demonstrations."""
660
661
print ("=" * 80 )
661
662
print ("VON NEUMANN CELLULAR AUTOMATON - FEATURE DEMONSTRATION" )
@@ -672,7 +673,7 @@ def demonstrate_cellular_automaton_features():
672
673
print ("=" * 80 )
673
674
674
675
675
- def quick_demo (rule_name : str = "conway" ):
676
+ def quick_demo (rule_name : str = "conway" ) -> None :
676
677
"""
677
678
Quick demonstration function for specific rule sets.
678
679
0 commit comments