-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
78 lines (66 loc) · 2.87 KB
/
test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Test script for the Traffic Jam Puzzle AI for Project 1 of CSCI373 AI.
(c) 2016 Gary Chen
"""
from JamPuzzle import *
from JamAgent import *
# Initial State A
vehiclesA = [
Vehicle((3, 0), Orientations.vertical, VehicleTypes.car),
Vehicle((4, 0), Orientations.horizontal, VehicleTypes.car),
Vehicle((4, 1), Orientations.horizontal, VehicleTypes.car),
Vehicle((0, 2), Orientations.vertical, VehicleTypes.car),
Vehicle((1, 2), Orientations.horizontal, VehicleTypes.truck),
Vehicle((4, 2), Orientations.horizontal, VehicleTypes.car),
Vehicle((2, 4), Orientations.horizontal, VehicleTypes.truck),
Vehicle((5, 3), Orientations.vertical, VehicleTypes.car),
]
trafficJamA = JamPuzzle(6, 6, 5, vehiclesA)
# Initial State B
vehiclesB = [
Vehicle((0, 0), Orientations.vertical, VehicleTypes.truck),
Vehicle((1, 0), Orientations.vertical, VehicleTypes.truck),
Vehicle((2, 0), Orientations.vertical, VehicleTypes.car),
Vehicle((3, 0), Orientations.horizontal, VehicleTypes.truck),
Vehicle((3, 1), Orientations.horizontal, VehicleTypes.truck),
Vehicle((2, 2), Orientations.horizontal, VehicleTypes.car),
Vehicle((4, 2), Orientations.horizontal, VehicleTypes.car),
Vehicle((0, 3), Orientations.horizontal, VehicleTypes.car),
Vehicle((4, 3), Orientations.vertical, VehicleTypes.car),
Vehicle((2, 5), Orientations.horizontal, VehicleTypes.car),
]
trafficJamB = JamPuzzle(6, 6, 4, vehiclesB)
# Initial State C
vehiclesC = [
Vehicle((0, 3), Orientations.vertical, VehicleTypes.truck),
Vehicle((1, 2), Orientations.vertical, VehicleTypes.truck),
Vehicle((2, 0), Orientations.vertical, VehicleTypes.truck),
Vehicle((2, 3), Orientations.horizontal, VehicleTypes.truck),
Vehicle((3, 0), Orientations.horizontal, VehicleTypes.truck),
Vehicle((3, 1), Orientations.vertical, VehicleTypes.car),
Vehicle((3, 4), Orientations.horizontal, VehicleTypes.truck),
Vehicle((4, 1), Orientations.horizontal, VehicleTypes.car),
Vehicle((5, 2), Orientations.vertical, VehicleTypes.car),
]
trafficJamC = JamPuzzle(6, 6, 5, vehiclesC)
def printSolution(puzzle, solution):
"""Method that takes an initial puzzle and array of solution Move
objects and applies the solution to the puzzle while printing out
the state and next move details for each move.
"""
for m in solution:
print(puzzle)
puzzle.move(m.pos, m.moves)
print(m)
print(puzzle)
print("Puzzle completed in " + str(len(solution)) + " moves.")
print("Number of nodes visited in search: " + str(agent.nodesVisited))
# Create AI agent and run on specified puzzles
agent = JamAgent()
solution = agent.bfs(trafficJamA)
printSolution(trafficJamA, solution)
print("****************************************")
solution = agent.bfs(trafficJamB)
printSolution(trafficJamB, solution)
print("****************************************")
solution = agent.bfs(trafficJamC)
printSolution(trafficJamC, solution)