-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainClass.java
56 lines (48 loc) · 2.01 KB
/
MainClass.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
46
47
48
49
50
51
52
53
54
55
56
import java.util.ArrayList;
import java.util.Stack;
public class MainClass {
/**
* Metoda scrie in fisierul writer rezolvarea labirintului pentru taskul 1
* @param maze labirintul
* @param writer fisierul de output
*/
public static void task1(Maze maze, HomeworkWriter writer) {
Direction start = new Direction(0, 0);
maze.getEntrance(start); // obtinem pozitia portalului de intrare
ArrayList<Direction> moves = new ArrayList<>();
moves = Task1.findPath(maze, start); //determinam drumul eroului
//afisam lungimea drumului si pe acesta
writer.println(String.valueOf(moves.size()));
for(Direction dir : moves)
writer.println(dir.row + " " + dir.col);
}
/**
* Metoda scrie in fisierul writer rezolvarea labirintului pentru taskul 1
* @param maze labirintul
* @param writer fisierul de output
*/
public static void task2(Maze maze, HomeworkWriter writer) {
Direction start = new Direction(0, 0);
maze.getEntrance(start); // obtinem pozitia portalului de intrare
Stack<Direction> shortestPath = new Stack<>();
shortestPath = Task2.findShortestPath(maze, start); //calculam cel
// mai scrurt drum
//afisam lungimea drumului si pe acesta
writer.println(String.valueOf(shortestPath.size()));
while (!shortestPath.isEmpty()){
Direction path = shortestPath.pop();
writer.println(path.row + " " + path.col);
}
}
public static void main(String[] args) throws Exception {
HomeworkReader reader = new HomeworkReader(args[1]);
HomeworkWriter writer = new HomeworkWriter(args[2]);
Maze maze = reader.readData();
if (args[0].equals("1"))
task1(maze, writer);
if (args[0].equals("2"))
task2(maze, writer);
reader.close();
writer.close();
}
}