|
1 | 1 | '''
|
2 | 2 | Team 4 - Ben Duggan & Connor Altic
|
3 |
| - 12/10/18 |
| 3 | + 8/17/19 |
4 | 4 | Class with main gui class
|
5 | 5 | '''
|
6 | 6 |
|
7 |
| -import time |
| 7 | +import time, argparse |
8 | 8 | from main_gui import *
|
9 | 9 | from AIs import *
|
10 | 10 | from Heuristic import *
|
@@ -79,40 +79,23 @@ def ai(type, n, scramble_length, heuristic):
|
79 | 79 | if __name__ == '__main__':
|
80 | 80 | # Ask the user what they want to run and run it for them
|
81 | 81 |
|
82 |
| - #x,n,scramble,heuristic = 'ida*',2,12,Heuristic.manhattanDistance |
83 |
| - x,n,scramble,heuristic = None,None,None,None |
84 |
| - if len(sys.argv) >= 2: |
85 |
| - x = sys.argv[1] |
86 |
| - if len(sys.argv) >= 3: |
87 |
| - n = int(sys.argv[2]) |
88 |
| - if len(sys.argv) >= 4: |
89 |
| - scramble = int(sys.argv[3]) |
90 |
| - if len(sys.argv) >= 5: |
91 |
| - if sys.argv[4] == 's': |
92 |
| - heuristic = Heuristic.simpleHeuristic |
93 |
| - elif sys.argv[4] == 'h': |
94 |
| - heuristic = Heuristic.hammingDistance |
95 |
| - else: |
96 |
| - heuristic = Heuristic.manhattanDistance |
97 |
| - elif x == None or n == None: |
98 |
| - print("(h)uman (gui) | (bfs), (bbfs), (a*), (ida*), (mini)") |
99 |
| - x = input() |
100 |
| - print("what nxn (just n)?") |
101 |
| - n = int(input()) |
102 |
| - print("what scramble length?") |
103 |
| - scramble = int(input()) |
104 |
| - print("What heuristic? (s)impleHeuristic, (h)ammingDistance, (m)anhattanDistance") |
105 |
| - h = input() |
106 |
| - if h == 's': |
107 |
| - heuristic = Heuristic.simpleHeuristic |
108 |
| - elif h == 'h': |
109 |
| - heuristic = Heuristic.hammingDistance |
110 |
| - else: |
111 |
| - heuristic = Heuristic.manhattanDistance |
| 82 | + parser = argparse.ArgumentParser(description='CubeAI\nCSCI-B 351 final project with the goal of making an AI to solve a 2x2 cube and possibly scaling up to higher order cubes. The AI algorithms used are BFS, Better BFS (limit moves), A*, IDA*, and Mini (a minimizing version of MiniMax). There are 3 heuristics implimented: simpleHeuristic, hammingDistance and manhattanDistance. ', formatter_class=argparse.RawTextHelpFormatter) |
| 83 | + parser.add_argument('--m', metavar='False', default=False, type=bool, action='store', help='Run manually (start gui) or run the AI first') |
| 84 | + parser.add_argument('--n', metavar='2', default=2, type=int, action='store', help='The dimension of the cube (nxn)') |
| 85 | + parser.add_argument('--s', metavar='5', default=5, type=int, action='store', help='How many times to scramble the cube') |
| 86 | + parser.add_argument('--a', metavar='ida*', default='ida*', type=str, action='store', help='Which AI algorithm to use: (bfs), (bbfs), (a*), (ida*), (mini)') |
| 87 | + parser.add_argument('--h', metavar='m', default='m', type=str, action='store', help='Which heuristic to use: (s)impleHeuristic, (h)ammingDistance, (m)anhattanDistance.') |
112 | 88 |
|
113 |
| - assert type(x) == type('a') and type(n) == type(1) and type(scramble) == type(1) |
| 89 | + args = parser.parse_args() |
114 | 90 |
|
115 |
| - if x == 'h': |
116 |
| - gui(n, scramble) |
| 91 | + if args.h == 's': |
| 92 | + heuristic = Heuristic.simpleHeuristic |
| 93 | + elif args.h == 'h': |
| 94 | + heuristic = Heuristic.hammingDistance |
117 | 95 | else:
|
118 |
| - ai(x, n, scramble, heuristic) |
| 96 | + heuristic = Heuristic.manhattanDistance |
| 97 | + |
| 98 | + if args.m: |
| 99 | + gui(args.n, args.s) |
| 100 | + else: |
| 101 | + ai(args.a, args.n, args.s, heuristic) |
0 commit comments