-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMazeDomain.java
More file actions
85 lines (64 loc) · 1.65 KB
/
MazeDomain.java
File metadata and controls
85 lines (64 loc) · 1.65 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
package server_side;
import java.util.ArrayList;
public class MazeDomain implements Searchable { // build the maze
State intialstate; // start point
State goalstate; // end point
int arr[][] ; //buffer
State mat[][]; //the maze
public MazeDomain(String[] buffer,String[] buffer2,int arr[][]) {
super();
this.arr = arr;
mat = new State[4][4];
this.createmaze();
this.setniebores();
this.setIntialstate(mat[Integer.parseInt(buffer[0])][Integer.parseInt(buffer[1])]);
this.setGoalstate(mat[Integer.parseInt(buffer2[0])][Integer.parseInt(buffer2[1])]);
}
public void setIntialstate(State intialstate) {
this.intialstate = intialstate;
}
public void setGoalstate(State goalstate) {
this.goalstate = goalstate;
}
@Override
public ArrayList<State> getAllPossibleStates(State s) {
return s.ListOfChildren;
}
public void createmaze() {
for(int i =0;i<arr.length;i++)
{
for(int j=0;j<arr.length;j++)
{
mat[i][j]=new State(i,j,arr[i][j]);
}
}
}
public void setniebores() {
for(int i =0;i<arr.length;i++)
{
for(int j=0;j<arr.length;j++)
{
if(i!=0) {
mat[i][j].addtoListOfChildren(mat[i-1][j]);
}
if(j!=0) {
mat[i][j].addtoListOfChildren(mat[i][j-1]);
}
if(i!=arr.length-1) {
mat[i][j].addtoListOfChildren(mat[i+1][j]);
}
if(j!=arr.length-1) {
mat[i][j].addtoListOfChildren(mat[i][j+1]);
}
}
}
}
@Override
public State getInitialState() {
return this.intialstate;
}
@Override
public State getGoalState() {
return this.goalstate;
}
}