Skip to content

Commit c95c0a3

Browse files
committed
fixed main.py problems and added command line arguments
1 parent bd076b0 commit c95c0a3

File tree

5 files changed

+35
-71
lines changed

5 files changed

+35
-71
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
CSCI-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. There is a GUI which shows a 2D and 3D cube inaddition to the move states and allows for people to try to solve the cube in an easy way.
33

44
# How to run:
5-
First make sure you have pygames installed by running `pip install pygames`. The simplest way to run the code is by running `python main.py`. The console will then walk you through the options. Additionally you can use command line arguments. The first argument is the size of the cube n (nxn), then the scramble length, next the AI algorithm (bfs, bbfs, a\*, ida\*, mini) and finally the heuristic ((s)impleHeuristic, (h)ammingDistance, (m)anhattanCube).
5+
First make sure you have pygames installed by running `pip install pygames`. The simplest way to run the code is by running `python main.py`. To view the command line arguments type `python main.py -h`. This will show the help page which is shown below:
6+
```
7+
CubeAI
8+
CSCI-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.
9+
10+
optional arguments:
11+
-h, --help show this help message and exit
12+
--m False Run manually (start gui) or run the AI first
13+
--n 2 The dimension of the cube (nxn)
14+
--s 5 How many times to scramble the cube
15+
--a ida* Which AI algorithm to use: (bfs), (bbfs), (a*), (ida*), (mini)
16+
--h m Which heuristic to use: (s)impleHeuristic, (h)ammingDistance, (m)anhattanDistance.
17+
```
18+
619

720
# Example images:
8-
![3D 2x2 GUI](/project_files/images/3d_2x2.png)
21+
![3D 2x2 GUI](/docs/images/3d_2x2.png)
922
3D 2X2 cube in GUI
10-
![2D 2x2 GUI](/project_files/images/2d_2x2.png)
23+
![2D 2x2 GUI](/docs/images/2d_2x2.png)
1124
2D 2x2 cube in GUI
1225

1326
# Documentation:

docs/2d_2x2.png

20.3 KB
Loading

docs/3d_2x2.png

33.8 KB
Loading

main.py

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'''
22
Team 4 - Ben Duggan & Connor Altic
3-
12/10/18
3+
8/17/19
44
Class with main gui class
55
'''
66

7-
import time
7+
import time, argparse
88
from main_gui import *
99
from AIs import *
1010
from Heuristic import *
@@ -79,40 +79,23 @@ def ai(type, n, scramble_length, heuristic):
7979
if __name__ == '__main__':
8080
# Ask the user what they want to run and run it for them
8181

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.')
11288

113-
assert type(x) == type('a') and type(n) == type(1) and type(scramble) == type(1)
89+
args = parser.parse_args()
11490

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
11795
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)

test.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)