-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodFF.cpp
98 lines (79 loc) · 1.72 KB
/
modFF.cpp
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
92
93
94
95
96
97
98
#include <stdio.h>
int main(void)
{
int grid = 6;
int ff[grid][grid];
//int walls[grid][grid];
//int walls[6][6] = {{11,8,10,8,10,12},{9,6,9,2,12,5},{5,13,1,14,3,4},{0,1,5,9,12,5},{5,3,6,5,5,5},{3,10,10,6,3,6}};
int walls[6][6] = {{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,2,0},{0,0,0,0,8,0},{0,0,0,4,5,1},{0,0,0,4,1,0}};
for(int i=0;i<grid;i++)
{
for (int j=0;j<grid;j++)
{
ff[i][j] = 0;
//walls[i][j] = 0;
}
}
int n = 1; //goal value
ff[5][0] = n; //setting location of goal
while (n < 50)
{
for(int i=0; i<grid;i++)
{
for (int j=0; j<grid;j++)
{
if ((ff[i][j]) == n)
{
if (i+1<grid) //CHECK SOUTH
{
if (ff[i+1][j] != 1 && ff[i+1][j] == 0 && (walls[i][j] & 2) == 0)
{
ff[i+1][j] = n+1;
}
}
if ((i-1)>-1) //CHECK NORTH
{
if (ff[i-1][j] != 1 && ff[i-1][j] == 0 && (walls[i][j] & 8) == 0)
{
ff[i-1][j] = n+1;
}
}
if ((j+1)<grid) //CHECK EAST
{
if (ff[i][j+1] != 1 && ff[i][j+1] == 0 && (walls[i][j] & 4)== 0)
{
ff[i][j+1] = n+1;
}
}
if ((j-1)>-1) //CHECK WEST
{
if (ff[i][j-1] != 1 && ff[i][j-1] == 0 && (walls[i][j] & 1) == 0)
{
ff[i][j-1] = n+1;
}
}
}
}
}
n++;
}
for(int i=0;i<grid;i++)
{
for (int j=0;j<grid;j++)
{
//printf("%d\t",ff[i][j]);
printf("%d\t",walls[i][j]);
}
printf("\n");
}
printf("\n\n");
for(int i=0;i<grid;i++)
{
for (int j=0;j<grid;j++)
{
printf("%d\t",ff[i][j]);
//printf("%d\t",walls[i][j]);
}
printf("\n");
}
}