-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulate.py
executable file
·63 lines (51 loc) · 1.68 KB
/
simulate.py
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
#!/usr/bin/env python3
import subprocess
import re
import json
import os
from collections import Counter
def get_all_teams(directory):
teams = set()
for filename in os.listdir(directory):
if filename.endswith(".json"):
with open(os.path.join(directory, filename), 'r') as f:
data = json.load(f)
if 'Name' in data:
teams.add(data['Name'])
return teams
def run_process_and_get_champion():
# Prepare the command
command = ['./bin/bsim']
command.append('--non-interactive')
# Run the process and capture the output
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
output = result.stdout
# Find the champion using regex
match = re.search(r'The champion: \[([^\]]+)\]!', output)
if match:
return match.group(1)
else:
return None
def main():
# Get all teams from the JSON files
all_teams = get_all_teams('./teams')
champions = []
# Run the process 1000 times
for i in range(1000):
champion = run_process_and_get_champion()
if champion:
champions.append(champion)
else:
print(f"Run {i+1}: No champion found")
# Count occurrences of each champion
champion_count = Counter(champions)
# Ensure all teams are included in the final ranking
for team in all_teams:
if team not in champion_count:
champion_count[team] = 0
# Print the ranking
print("Ranking of champions from most to least:")
for team, count in champion_count.most_common():
print(f"{team}: {count} times")
if __name__ == "__main__":
main()