This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsolver.py
126 lines (108 loc) · 3.56 KB
/
solver.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
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
import utility
import subprocess
import time
import pyautogui
import random
import sys, os
import keyboard
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/task-solvers")
from task_utility import get_dimensions, get_screen_coords, wake
def generate_files():
possible_tasks = utility.load_dict().keys()
for task in possible_tasks:
with open(f"task-solvers\{task}.py", "w") as f:
f.close()
def chat(can_vote_flag : bool):
if utility.isDead():
while utility.in_meeting():
if keyboard.is_pressed('`'):
raise SystemExit(0)
time.sleep(1/60)
continue
time.sleep(10)
return
p = subprocess.Popen(["python", f"chatGPT.py"])
while p.poll() is None:
if keyboard.is_pressed('`'):
p.kill()
utility.clear_kill_data()
return
p.wait()
while utility.in_meeting():
if keyboard.is_pressed('`'):
raise SystemExit(0)
time.sleep(1/60)
p.kill()
utility.clear_kill_data()
def solve_task(task_name=None, task_location=None) -> int:
"""
Runs the correct task solver file in a subprocess
Note - the AI only goes to the upper location of sabotages
Returns
--------
int
0 if success
1 if meeting was called or died
2 if a meeting was called and the task was inspect sample (so it doesn't wait later)
-1 if task not found
"""
dead : bool = utility.isDead()
if task_name == "vote":
print("Should never be here")
if not dead:
p = subprocess.Popen(["python", f"task-solvers\\vote.py"])
else:
return 0
p.wait()
return 0
if utility.isImpostor():
# Record last task done
if not utility.isDead():
with open("last_task.txt", "w") as f:
f.write(f"{task_name} in {task_location}")
f.close()
time.sleep(1.5)
urgent = utility.is_urgent_task()
if urgent is None:
# Open solver file
if random.randint(1,3) % 3 == 0:
p = subprocess.Popen(["python", f"task-solvers\Sabotage.py"])
else:
return 0
else:
if utility.in_meeting():
return 1
return 0
# Wait for process to finish
while p.poll() is None:
if utility.in_meeting() or keyboard.is_pressed('`'):
p.kill()
return 1
time.sleep(1/30)
time.sleep(3) # Fake doing stuff
return 0
if utility.is_urgent_task() is not None:
if task_name is not None and task_name != utility.is_urgent_task()[0]:
return 1
if task_name is not None and task_name != ():
# Record last task done
with open("last_task.txt", "w") as f:
f.write(f"{task_name} in {task_location}")
f.close()
# Open solver file
p = subprocess.Popen(["python", f"task-solvers\{task_name}.py"])
# Wait for process to finish
while p.poll() is None:
if utility.in_meeting() or (utility.isDead() != dead) or keyboard.is_pressed('`'):
p.kill()
if task_name == "Inspect Sample" or task_name == "Reboot Wifi":
return 2
else:
return 1
time.sleep(1/30)
if task_name == "Inspect Sample" or task_name == "Reboot Wifi":
return 2
else:
return 0
print("Task not found")
return -1