1 #include "kmap_struct.h"
2 #include "check_quad.h"
3 #include "quad_lib.h"
4 #include "g_library.h"
5
6
7
8
9
10
11 /*################ CHECKS THE QUAD AND RETURNS THE STATUS ##############*/
check_quad(int row,int col)12 void check_quad(int row,int col)
13 {
14 int row_status,col_status,left_down_status,left_up_status;
15 int right_down_status,right_up_status,quad_status;
16
17 if((row_status=chk_row_nzero(row,col))==FOUND)
18 {
19 quad_status=mk_hozntal_quad(row,col);
20 return;
21 }
22 if((col_status=chk_col_nzero(row,col))==FOUND)
23 {
24 quad_status=mk_vertical_quad(row,col);
25 return;
26 }
27 if((left_down_status=chk_lf_dn_quad(row,col))==FOUND)
28 {
29 quad_status=mk_lf_dn_quad(row,col);
30 return;
31 }
32 if((left_up_status=chk_lf_up_quad(row,col))==0)
33 {
34 quad_status=mk_lf_up_quad(row,col);
35 return;
36 }
37 if((right_down_status=chk_rt_dn_quad(row,col))==0)
38 {
39 quad_status=mk_rt_dn_quad(row,col);
40 return;
41 }
42 if((right_up_status=chk_rt_up_quad(row,col))==0)
43 {
44 quad_status=mk_rt_up_quad(row,col);
45 return;
46 }
47 return;
48 }
49
50
mk_hozntal_quad(int row,int col)51 int mk_hozntal_quad(int row,int col)
52 {
53 connection++;
54 save_key_hz_vrt(row,col,HZNTL);
55 save_cellno_hz_vrt(row,col,HZNTL);
56 set_all_x_hz_vr(row,col,HZNTL);
57 set_status_active();
58 return 0;
59 }
60
61
mk_vertical_quad(int row,int col)62 int mk_vertical_quad(int row,int col)
63 {
64 connection++;
65 save_key_hz_vrt(row,col,VRTCL);
66 save_cellno_hz_vrt(row,col,VRTCL);
67 set_all_x_hz_vr(row,col,VRTCL);
68 set_status_active();
69 return 0;
70 }
71
72
mk_lf_dn_quad(int row,int col)73 int mk_lf_dn_quad(int row,int col)
74 {
75 connection++;
76 save_key_lf_dn(row,col);
77 save_cellno_lf_dn(row,col);
78 set_all_x_lf_dn(row,col);
79 set_status_active();
80 return 0;
81 }
82
mk_lf_up_quad(int row,int col)83 int mk_lf_up_quad(int row,int col)
84 {
85 connection++;
86 save_key_lf_up(row,col);
87 save_cellno_lf_up(row,col);
88 set_all_x_lf_up(row,col);
89 set_status_active();
90
91 return 0;
92 }
mk_rt_up_quad(int row,int col)93 int mk_rt_up_quad(int row,int col)
94 {
95 connection++;
96 save_key_rt_up(row,col);
97 save_cellno_rt_up(row,col);
98 set_all_x_rt_up(row,col);
99 set_status_active();
100 return 0;
101 }
102
mk_rt_dn_quad(int row,int col)103 int mk_rt_dn_quad(int row,int col)
104 {
105 connection++;
106 save_key_rt_dn(row,col);
107 save_cellno_rt_dn(row,col);
108 set_all_x_rt_dn(row,col);
109 set_status_active();
110 return 0;
111 }
112
113
114 /*######################## Check left down quad ########################*/
chk_lf_dn_quad(int row,int col)115 int chk_lf_dn_quad(int row,int col)
116 {
117 int new_row,new_col;
118 new_row=get_new_row(row,LOWER);
119 new_col=get_new_col(col,LEFT);
120 if(((cell_array[row][col].value=='1')||(cell_array[row][col].value=='X'))
121 &&((cell_array[row][new_col].value=='1')||(cell_array[row][new_col].value=='X'))
122 &&((cell_array[new_row][new_col].value=='1')||(cell_array[new_row][new_col].value=='X'))
123 &&((cell_array[new_row][col].value=='1')||(cell_array[new_row][col].value=='X')))
124 return FOUND;
125 else
126 return N_FOUND;
127 }
128
129
130
131 /*######################## Check left up quad ########################*/
chk_lf_up_quad(int row,int col)132 int chk_lf_up_quad(int row,int col)
133 {
134 int new_row,new_col;
135 new_row=get_new_row(row,UPPER);
136 new_col=get_new_col(col,LEFT);
137 if(((cell_array[row][col].value=='1')||(cell_array[row][col].value=='X'))
138 &&((cell_array[row][new_col].value=='1')||(cell_array[row][new_col].value=='X'))
139 &&((cell_array[new_row][new_col].value=='1')||(cell_array[new_row][new_col].value=='X'))
140 &&((cell_array[new_row][col].value=='1')||(cell_array[new_row][col].value=='X')))
141 return FOUND;
142 else
143 return N_FOUND;
144 }
145
146 /*######################## Check right up quad ########################*/
chk_rt_up_quad(int row,int col)147 int chk_rt_up_quad(int row,int col)
148 {
149 int new_row,new_col;
150 new_row=get_new_row(row,UPPER);
151 new_col=get_new_col(col,RIGHT);
152 if(((cell_array[row][col].value=='1')||(cell_array[row][col].value=='X'))
153 &&((cell_array[row][new_col].value=='1')||(cell_array[row][new_col].value=='X'))
154 &&((cell_array[new_row][new_col].value=='1')||(cell_array[new_row][new_col].value=='X'))
155 &&((cell_array[new_row][col].value=='1')||(cell_array[new_row][col].value=='X')))
156 return FOUND;
157 else
158 return N_FOUND;
159 }
160
161 /*######################## Check right down quad ########################*/
chk_rt_dn_quad(int row,int col)162 int chk_rt_dn_quad(int row,int col)
163 {
164 int new_row,new_col;
165 new_row=get_new_row(row,LOWER);
166 new_col=get_new_col(col,RIGHT);
167
168 if(((cell_array[row][col].value=='1')||(cell_array[row][col].value=='X'))
169 &&((cell_array[row][new_col].value=='1')||(cell_array[row][new_col].value=='X'))
170 &&((cell_array[new_row][new_col].value=='1')||(cell_array[new_row][new_col].value=='X'))
171 &&((cell_array[new_row][col].value=='1')||(cell_array[new_row][col].value=='X')))
172 return FOUND;
173 else
174 return N_FOUND;
175 }
176