-
Notifications
You must be signed in to change notification settings - Fork 0
/
HEX.py
55 lines (52 loc) · 1.9 KB
/
HEX.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
import subprocess
import time
import helpers
def checkSolution(last=False):
badSolution = ['WRONG', 'URONG', 'CODE!', 'WROMG']
screen = helpers.ocr(20, 2.1, 3.4, 2)
response = helpers.formatOcr(screen)
for item in response:
if item in badSolution:
print('[HEX.py] Wrong solution! Trying lower possibility')
if last:
return solve()
return False
return True
def solve():
helpers.inputText(['HEX'])
start_time = time.time()
screen = helpers.ocr(20, 3.7, 1.8, 2.2)
ocr_time = time.time()
puzzle = helpers.formatOcr(screen, 'hex', 2)
solutionBest = []
solutionMaybe = []
solutionLow = []
for number in puzzle:
if number != '':
if puzzle.count(number) > 4:
if number not in solutionBest:
solutionBest.append(number)
if puzzle.count(number) == 4:
if number not in solutionMaybe:
solutionMaybe.append(number)
if puzzle.count(number) == 3:
if number not in solutionLow:
solutionLow.append(number)
solution_time = time.time()
print('[HEX.py] SOLUTION:')
print('[HEX.py] Best: ', solutionBest, ' Maybe: ', solutionMaybe, ' Low: ', solutionLow)
if solutionBest:
helpers.inputText(solutionBest)
elif solutionMaybe:
helpers.inputText(solutionMaybe)
correct = checkSolution()
if not correct:
helpers.inputText(solutionLow)
checkSolution(True)
input_time = time.time()
print('[HEX.py] Hex solve times:')
print('[HEX.py] OCR time:', round((ocr_time - start_time), 4))
print('[HEX.py] Solution time:', round((solution_time - ocr_time), 4))
print('[HEX.py] Input time:', round((input_time - solution_time), 4))
print('[HEX.py] Total:', round((time.time() - start_time), 4))
return True