TUYỂN TẬP 25 ĐỀ THI HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2023 CÓ ĐÁP ÁN (SƯU...
Laporan ai modul 3-if b 2014-14102055-deprilana ego prakasa
1. Sekolah Tinggi Teknologi Telematika Telkom
Laporan Praktikum
Kecerdasan Buatan
Modul 3 – Implementasi DFS dan BFS pada
Permainan Labirin
Dosen Pengampu: Muhammad Zidny Naf’an,S.Kom., M.Kom.
Nama Mahasiswa : Deprilana Ego Prakasa
NIM : 14102055
Kelas : S1 IF B 2014
2. Jawaban Latihan Soal
1. Berdasarkan pohon pelacakan di atas, hasil penelusuran metode DFS adalah
: (1,1), (1,2), (2,1), (3,1), (3,2), (3,3), (3,4), (4,3)
2. Berdasarkan pohon pelacakan di atas, hasil penelusuran metode BFS adalah :
(1,1), (1,2), (2,1), (3,1), (3,2), (4,1), (3,3), (3,4), (4,3)
3. Jalankan program yang telah dibuat, hasilnya :
Node.java
package AIDFSBFS;
import java.util.ArrayList;
import java.util.List;
public class Node {
int row;
int col;
3. boolean wasVisited;
String label;
List<Node> adjNode;
Node(int row, int col)
{ this.row = row;
this.col = col;
this.label = "("+Integer.toString(row)+","+Integer.toString(col)+")";
this.wasVisited = false;
adjNode = new ArrayList<Node>();
}
}
MazeSolver.java
package AIDFSBFS;
import java.util.ArrayList;
import java.util.List; import
java.util.LinkedList; import
java.util.Queue; import
java.util.Stack;
public class MazeSolver
{
private int
myMaze[][]={{1,1,1,1,1},
{1,0,0,1,0}, {1,0,1,1,1},
{1,0,0,0,0}, {1,0,1,0,1}};
List<Node> nodes;
String moveOrder;
private final int MAX_ROWS=5, MAX_COLS=5;
private int newRow, newCol;
Stack<Node> stackNodes;
Queue<Node> queueNodes;
List<Node> listVisitedNodes;
Node startNode;
Node goalNode;
public MazeSolver(String moveOrder)
4. {
super();
nodes = new ArrayList<Node>();
stackNodes = new Stack<Node>();
queueNodes = new LinkedList<Node>();
listVisitedNodes = new
ArrayList<Node>(); this.moveOrder =
moveOrder; generateNode();
generateAdjacentNode();
}
private boolean isPossibleMove(int row, int col, char direction)
{
boolean possible = false;
switch(direction)
{
case 'N':
if(row-1>=0 && myMaze[row-1][col] == 0)
possible = true;
newRow = row-1;
newCol = col;
break;
case 'S':
if(row+1<MAX_ROWS && myMaze[row+1][col] ==
0) possible = true;
newRow = row+1;
newCol = col;
break;
case 'E':
if(col+1<MAX_COLS && myMaze[row][col+1] ==
0) possible = true;
newRow = row;
newCol = col+1;
break;
case 'W':
if(col-1>=0 && myMaze[row][col-1] == 0)
possible = true;
newRow = row;
newCol = col-1;
break;
}
return possible;
}
private void generateNode()
{
for(int i=0; i<MAX_ROWS; i++)
{
for(int j=0; j<MAX_COLS; j++)
19. (0,2), (1,2), (1,3), (2,3), (3,3), (3,4), (4,4)
8. Hasil penelusuran BFS dengan urutan operator NORTH-SOUTH-EAST-WEST : (0,2),
(1,2), (1,3), (1,1), (2,3), (2,1), (1,0), (3,3), (3,1), (0,0), (3,4), (3,2), (4,1), (4,4)
9. Kesimpulan anda ?
- Pada metode DFS, program akan menelusuri suatu node sampai ke child yang paling
ujung sebelum melanjutkan ke node selanjutnya yang levelnya lebih tinggi.
- Pada metode BFS, program akan melakukan pencarian dimulai dari node-node
dengan level paling tinggi sebelum menuju ke node dengan level yang lebih rendah