-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapAstar.java
More file actions
81 lines (75 loc) · 2.07 KB
/
MapAstar.java
File metadata and controls
81 lines (75 loc) · 2.07 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
/* Written by Junyoung Justin Kim */
/* lawsonNavigator-server */
/* Map file reading */
/* Last Update : Nov, 1 */
//Modifed to be implemented with A* by George Brinzea
package com.purdue.LawsonNavigator;
import java.io.*;
import java.util.*;
public class MapAstar{
public static int[][] generateGrid(int choice, int col, int row){
//int col = 27; // There are 27 columns in the map file
//int row = 61; // There is 61 rows in the map file
int floorB[][] = new int[row][col]; // basement floor
int floor1[][] = new int[row][col]; // 1st floor
int floor2[][] = new int[row][col]; // 2nd floor
int floor3[][] = new int[row][col]; // 3rd floor
int i, j, temp; // i, j for array index to reading file
File fileB = new File ("floorB.txt");
File file1 = new File ("floor1.txt");
File file2 = new File ("floor2.txt");
File file3 = new File ("floor3.txt");
Scanner scanB;
Scanner scan1;
Scanner scan2;
Scanner scan3;
try {
scanB = new Scanner (fileB);
scan1 = new Scanner (file1);
scan2 = new Scanner (file2);
scan3 = new Scanner (file3);
if(choice == 0){
// Reading Basement floor
i = 0; j = 0;
while (scanB.hasNextInt()) {
temp = scanB.nextInt();
floorB[j][i] = temp; i++;
if (i == col){ j++; i = 0; }
}
return floorB;
}else if(choice == 1){
// Reading 1st Floor
i = 0; j = 0;
while (scan1.hasNextInt()) {
temp = scan1.nextInt();
floor1[j][i] = temp; i++;
if (i == col){ j++; i = 0; }
}
return floor1;
}else if(choice == 2){
// Reading 2nd Floor
i = 0; j = 0;
while (scan2.hasNextInt()) {
temp = scan2.nextInt();
floor2[j][i] = temp; i++;
if (i == col){ j++; i = 0; }
}
return floor2;
}else if(choice == 3){
// Reading 3rd Floor
i = 0; j = 0;
while (scan3.hasNextInt()) {
temp = scan3.nextInt();
floor3[j][i] = temp; i++;
if (i == col){ j++; i = 0; }
}
return floor3;
}
} catch (Exception e){
System.err.println("I/O Error.");
e.printStackTrace();
System.exit(1);
}
return null;
}
}