-
Notifications
You must be signed in to change notification settings - Fork 0
/
MazeSolverDFS.java
45 lines (42 loc) · 1.23 KB
/
MazeSolverDFS.java
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
/*
* c3309266
* Akshata Dhuraji
* COMP2230 Assignment
*/
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
public class MazeSolverDFS {
/**
* Main driver method of MazSolverDFS app
* @param args command line arguments
*/
public static void main(String[] args) {
// validating number of arguments
if (args.length != 1) {
throw new IllegalArgumentException("Illegal number of command line arguments. 1 argument expected");
}
// scanning input file
try (Scanner scanner = new Scanner(new File(args[0]))) {
// creating maze
Maze maze = new Maze(scanner.nextLine());
// starting time count
long start = System.currentTimeMillis();
// solving maze
List<Integer> result = maze.solve();
// stopping time count
long time = System.currentTimeMillis() - start;
// outputting result path
System.out.println("(" + result.stream().map(i -> Integer.toString(i)).collect(Collectors.joining(",")) + ")");
// showing path length
System.out.println(result.size() - 1);
// showing time used
System.out.println(time);
}
catch (IOException ignored) {
throw new IllegalArgumentException("Can not open input file");
}
}
}