-
Notifications
You must be signed in to change notification settings - Fork 1
/
solver.py
65 lines (54 loc) · 2.06 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sys import exit as Die
try:
import sys
import kociemba
import argparse
import video as webcam
from combiner import combine
from normalizer import normalize
except ImportError as err:
Die(err)
class Solver:
def __init__(self, normalize, language):
self.humanize = normalize
self.language = (language[0]) if isinstance(language, list) else language
def run(self):
state = webcam.scan()
if not state:
print('\033[0;33m[Solver SCAN ERROR] Ops, you did not scan in all 6 sides.')
print('Please try again.\033[0m')
Die(1)
unsolvedState = combine.sides(state)
try:
algorithm = kociemba.solve(unsolvedState)
length = len(algorithm.split(' '))
except Exception as err:
print('\033[0;33m[Solver SOLVE ERROR] Ops, you did not scan in all 6 sides correctly.')
print('Please try again.\033[0m')
Die(1)
print('-- SOLUTION --')
print('Starting position:\n front: green\n top: white\n')
print(algorithm, '({0} moves)'.format(length), '\n')
# if self.humanize:
manual = normalize.algorithm(algorithm, self.language)
for index, text in enumerate(manual):
print('{}. {}'.format(index+1, text))
Die(0)
if __name__ == '__main__':
# define argument parser.
parser = argparse.ArgumentParser()
parser.add_argument('-n', '--normalize', default=False, action='store_true',
help='Shows the solution normalized. For example "R2" would be: \
"Turn the right side 180 degrees".')
parser.add_argument('-l', '--language', nargs=1, default='en',
help='You can pass in a single \
argument which will be the language for the normalization output. \
Default is "en".')
args = parser.parse_args()
# run Solver with its arguments.
Solver(
args.normalize,
args.language
).run()