-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (41 loc) · 1.5 KB
/
main.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
from os import system, name
import gridgenerator
import oneDimension
import twodimensions
clearConsole = lambda: system('cls' if name in ('nt', 'dos') else 'clear')
def showMainScreen():
print("\nHOSHEN - KOPELMAN ALGORITHM IMPLEMENTATION\nby Mohammad Yasir, M. Sc. Physics\n")
print("""To continue, make a choice per the following:
1. One dimension implementation:
1.1. For a randomly generated matrix.
1.2. For a user-input matrix.
2. Two dimensions implementation:
2.1 For a randomly generated matrix.
2.2. For a user-input matrix.
3. Exit the program.""")
choice = float(input("Enter your choice... "))
if choice not in (1.1, 1.2, 2.1, 2.2, 3):
print("You have entered an incorrect choice. Press enter to retry...")
delay = input()
return False
else:
return choice
gridDictionary = {
1.1: gridgenerator.oneDimensionRandom, 1.2: gridgenerator.oneDimensionInput,
2.1: gridgenerator.twoDimensionRandom, 2.2: gridgenerator.twoDimensionInput
}
while True:
clearConsole()
choice = showMainScreen()
if not choice:
continue
if choice == 3:
break
matrix = gridDictionary.get(key = choice)()
if choice in (1.1, 1.2):
oneDimension.countClusters(matrix)
else:
twodimensions.countClusters(matrix)
restart = str(input("Program has finished execution. Would you like to restart? (Y/N)... "))
if restart not in ('Y', 'y'):
break