-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArgs.py
49 lines (41 loc) · 2.12 KB
/
Args.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
import os
import signal
from argparse import ArgumentParser
class Args:
def __init__(self):
# Parsing arguments
self.parser = ArgumentParser(description="Euler's Horse by Martin Szabo")
self.parser.add_argument("-t", "--timeout", dest="timeout", help="How long should the program wait before time out")
self.parser.add_argument("-d", "--depth", dest="depth", help="Maximum recursion depth. Increase this with large "
"chessboard proportions")
self.parser.add_argument("-W", "--width", dest="board_width", help="Chessboard width")
self.parser.add_argument("-H", "--height", dest="board_height", help="Chessboard height")
self.parser.add_argument("-X", "--start-x", dest="start_x", help="Starting X coordinate")
self.parser.add_argument("-Y", "--start-y", dest="start_y", help="Starting Y coordinate")
self.parser.add_argument("-r", "--random-start", dest="random_start", action="store_true",
help="Generate 10 random starting points (Ignores manually entered starting points")
args_dict = self.parser.parse_args().__dict__
for k, v in args_dict.items():
setattr(self, k, v)
def parse_int(self, arg, default_value):
value = self.__convert_arg_to_int(arg)
value = value if value is not None else default_value
return value
def __convert_arg_to_int(self, arg):
if arg is not None:
try:
return int(arg)
except ValueError:
print("Could not convert argument value \"{}\" to integer value!".format(arg))
if not self.__get_confirmation():
pid = os.getpid()
os.kill(pid, signal.SIGTERM)
print("Using default value...\n")
return None
@staticmethod
def __get_confirmation():
response = ''
while response != 'Y' and response != 'N':
print("Do you wish to continue? (y/n): ", end='')
response = input().upper()
return response == 'Y'