-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
91 lines (62 loc) · 1.98 KB
/
Copy pathmain.cpp
File metadata and controls
91 lines (62 loc) · 1.98 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
#include <iostream>
#include <fstream>
#include "Way.h"
#include "Maze.h"
using namespace std;
void inputfile() { //Fungsi untuk input lewat file
string filein;
string fileout;
cout << "Masukan nama file: ";
cin >> filein;
Maze maze(filein);
cout << endl;
maze.printMaze();
cout << endl;
cout << "Titik start adalah (" << maze.getStart().x << "," << maze.getStart().y << ")" << endl;
cout << "Titik finish adalah (" << maze.getFinish().x << "," << maze.getFinish().y << ")" << endl;
Way way(maze);
int step = way.BFS(maze);
if (step != -1) cout << "Langkah terpendek sebanyak " << step << endl;
else cout << "Langkah terpendek tidak ada" << endl;
cout << endl;
way.solveMaze(maze);
cout << "Masukan nama file output : ";
cin >> fileout;
maze.foutMaze(fileout);
}
void inputmanual() { //Fungsi untuk input manual
Maze maze;
maze.inputManual();
cout << "Titik start adalah (" << maze.getStart().x << "," << maze.getStart().y << ")" << endl;
cout << "Titik finish adalah (" << maze.getFinish().x << "," << maze.getFinish().y << ")" << endl;
Way way(maze);
int step = way.BFS(maze);
if (step != -1) cout << "Langkah terpendek sebanyak " << step << endl;
else cout << "Langkah terpendek tidak ada" << endl;
cout << endl;
way.solveMaze(maze);
for(int i=0; i<maze.getRow(); i++)
{
for(int j=0; j<maze.getCol(); j++)
{
if (maze.getMaze()[i][j] == 0) cout<<"#";
if (maze.getMaze()[i][j] == 2) cout << "!";
if (maze.getMaze()[i][j] == 1 && i != maze.getStart().x && i != maze.getFinish().x) cout << "-";
if (i == maze.getStart().x && j == maze.getStart().y) cout << "S";
if (i == maze.getFinish().x && j== maze.getFinish().y) cout << "D";
}
cout << endl;
}
}
int main() {
int x;
string filein;
string fileout;
cout << "Apakah anda mau input file atau manual" << endl;
cout << "1 = input file 2 = input manual" << endl;
cin >>x;
if (x==1) inputfile();
else if (x==2) inputmanual();
else cout <<"error";
return 0;
}