-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunMaze.java
More file actions
109 lines (83 loc) · 2.32 KB
/
RunMaze.java
File metadata and controls
109 lines (83 loc) · 2.32 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
RunMaze.java
Majority of code found online by Shawn Garrison
Editted to fit the project by George Brinzea
Handles running the alorithm to find a path
Turns the path into an array of directions to be used to create text or image directions
*/
package com.purdue.LawsonNavigator;
import java.util.*;
public class RunMaze {
/**
* @param args
*/
public static void main(String[] args) {
Maze maze1 = new Maze(61, 27);
//maze1.draw();
maze1.findBestPath();
List<Square> bestList = maze1.getBestList();
int directions[] = new int[bestList.size() - 1];
int j = 0;
for(int i = bestList.size() - 1; i > 0; i--){
//System.out.println("X: " + bestList.get(i).getX() + " Y: " + bestList.get(i).getY());
Square current = bestList.get(i);
Square next = bestList.get(i-1);
int dx = next.getX() - current.getX();
int dy = next.getY() - current.getY();
if(dx < 0){
directions[j] = 0;
}else if(dx > 0){
directions[j] = 2;
}else if(dy > 0){
directions[j] = 1;
}else{
directions[j] = 3;
}
j++;
}
for(int i = 0; i < directions.length; i++){
System.out.println(directions[i]);
}
}
public static int[] Run(int start1, int start2, int end1, int end2, int floor){
Maze maze = new Maze(61, 27, start1, start2, end1, end2, floor);
maze.draw();
maze.findBestPath();
List<Square> bestList = maze.getBestList();
int directions[] = new int[bestList.size()];
int j = 0;
int dx = bestList.get(bestList.size() - 1).getX() - start1;
int dy = bestList.get(bestList.size() - 1).getY() - start2;
if(dx < 0){
directions[j] = 0;
}else if(dx > 0){
directions[j] = 2;
}else if(dy > 0){
directions[j] = 1;
}else{
directions[j] = 3;
}
j++;
for(int i = bestList.size() - 1; i > 0; i--){
//System.out.println("X: " + bestList.get(i).getX() + " Y: " + bestList.get(i).getY());
Square current = bestList.get(i);
Square next = bestList.get(i-1);
dx = next.getX() - current.getX();
dy = next.getY() - current.getY();
if(dx < 0){
directions[j] = 0;
}else if(dx > 0){
directions[j] = 2;
}else if(dy > 0){
directions[j] = 1;
}else{
directions[j] = 3;
}
j++;
}
/*for(int i = 0; i < directions.length; i++){
System.out.println(directions[i]);
}*/
return directions;
}
}