-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlidingBoard.java
More file actions
48 lines (40 loc) · 1.95 KB
/
SlidingBoard.java
File metadata and controls
48 lines (40 loc) · 1.95 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
package slidingboard;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class SlidingBoard {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); //scanner for user input
System.out.println("Please enter the file name: ");
String fileName = scanner.nextLine();
try
{
Scanner read = new Scanner(new File(fileName)); //scanner for file
int n = read.nextInt(); //read number of rows
int m = read.nextInt(); //read number of columns
int[][] initial = new int[n][m]; //initial board
int[][] goal = new int[n][m]; //initial board
for(int i = 0; i < n; i++){ //step through file to
for(int j = 0; j < m; j++) //find every integer for
{ //the initial board
initial[i][j] = read.nextInt();
}
}
for(int i = 0; i < n; i++){ //step through file to
for(int j = 0; j < m; j++) //find every integer for
{ //the initial baord
goal[i][j] = read.nextInt();
}
}
SlidingDepthFirst s = new SlidingDepthFirst(initial, goal, n, m);
long startTime = System.currentTimeMillis();
s.solve(); //solve board
long endTime = System.currentTimeMillis();
System.out.println("Duration: " + (endTime - startTime) + " milliseconds using depth first");
}
catch (IOException e) //catch IO exception from the file input
{
System.out.println(e);
}
}
}