1 cap: proc (godatap);
2
3
4
5
6
7 %include godata;
8
9 dcl (i, ii, j, jj) fixed bin;
10 dcl (up_gp, lo_gp, lf_gp, rt_gp) fixed bin;
11 dcl temp fixed bin;
12
13 dcl EDGE fixed bin int static options (constant) init (0);
14
15
16
17
18 godata.ngrp = 0;
19 godata.dead (WHITE, 0), godata.dead (WHITE, 1), godata.dead (WHITE, 2) = 0;
20 godata.dead (BLACK, 0), godata.dead (BLACK, 1), godata.dead (BLACK, 2) = 0;
21 do i = 1 to 361;
22 godata.np (i) = 0;
23 godata.dame (WHITE, i), godata.dame (FREE, i), godata.dame (BLACK, i) = 0;
24 godata.dami1 (i), godata.dami2 (i), godata.damj1 (i), godata.damj2 (i) = 0;
25 godata.gp_color (i) = 0;
26 end;
27 do i = 1 to 19;
28 do j = 1 to 19;
29 godata.grpno (i, j) = 0;
30 end;
31 end;
32
33
34
35
36 do i = 1 to 19;
37 do j = 1 to 19;
38 up_gp, lf_gp = 0;
39
40
41 if i > 1 then
42 if board (i-1, j) = board (i, j) then do;
43 up_gp, grpno (i, j) = grpno (i-1, j);
44 np (up_gp) = np (up_gp) + 1;
45
46 if j > 1 then
47 if board (i, j-1) = board (i, j) then
48 if up_gp ^= grpno (i, j - 1) then do;
49 lf_gp = grpno (i, j-1);
50 temp = np (lf_gp);
51 do ii = i to 1 by -1 while (temp > 0);
52 do jj = 1 to 19 while (temp > 0);
53 if grpno (ii, jj) = lf_gp then do;
54 grpno (ii, jj) = up_gp;
55 temp = temp - 1;
56 end;
57 end;
58 end;
59 if gp_loc (up_gp, 1) < gp_loc (lf_gp, 1) then;
60 else if gp_loc (up_gp, 1) = gp_loc (lf_gp, 1) then
61 if gp_loc (up_gp, 2) < gp_loc (lf_gp, 2) then;
62 else go to swap;
63 else do;
64 swap: gp_loc (up_gp, 1) = gp_loc (lf_gp, 1); Note
65 gp_loc (up_gp, 2) = gp_loc (lf_gp, 2);
66 end;
67 np (up_gp) = np (up_gp) + np (lf_gp);
68 np (lf_gp) = 0;
69 gp_color (lf_gp) = -2;
70 end;
71
72 go to next_pt;
73 end;
74
75
76 if j > 1 then
77 if board (i, j-1) = board (i, j) then do;
78 grpno (i, j) = grpno (i, j-1);
79 np (grpno (i, j)) = np (grpno (i, j)) + 1;
80 go to next_pt;
81 end;
82
83
84 ngrp = ngrp + 1;
85 gp_loc (ngrp, 1) = i; Note
86 gp_loc (ngrp, 2) = j;
87 gp_color (ngrp) = board (i, j);
88 grpno (i, j) = ngrp;
89 np (ngrp) = 1;
90
91
92 next_pt:
93 end;
94 end;
95
96
97
98
99 do i = 1 to 19;
100 do j = 1 to 19;
101
102 up_gp, lo_gp, lf_gp, rt_gp = 0;
103
104 if i = 1 then contact (i, j, 1) = EDGE;
105 else do;
106 up_gp = grpno (i-1, j);
107 contact (i, j, 1) = up_gp;
108 if grpno (i, j) ^= up_gp then
109 call add_dame (up_gp);
110 end;
111
112 if i = 19 then contact (i, j, 3) = EDGE;
113 else do;
114 lo_gp = grpno (i+1, j);
115 contact (i, j, 3) = lo_gp;
116 if grpno (i, j) ^= lo_gp then do;
117 if lo_gp ^= up_gp then
118 call add_dame (lo_gp);
119 end;
120 end;
121
122 if j = 1 then contact (i, j, 2) = EDGE;
123 else do;
124 lf_gp = grpno (i, j-1);
125 contact (i, j, 2) = lf_gp;
126 if grpno (i, j) ^= lf_gp then do;
127 if lf_gp ^= up_gp then
128 if lf_gp ^= lo_gp then
129 call add_dame (lf_gp);
130 end;
131 end;
132
133 if j = 19 then contact (i, j, 4) = EDGE;
134 else do;
135 rt_gp = grpno (i, j+1);
136 contact (i, j, 4) = rt_gp;
137 if grpno (i, j) ^= rt_gp then do;
138 if rt_gp ^= up_gp then
139 if rt_gp ^= lo_gp then
140 if rt_gp ^= lf_gp then
141 call add_dame (rt_gp);
142 end;
143 end;
144
145 end;
146 end;
147
148
149
150 do i = 1 to ngrp;
151 if gp_color (i) ^= -2 then
152 if gp_color (i) ^= 0 then
153 if dame (0, i) <= 2 then do;
154 godata.dead (gp_color (i), dame (0, i)) = godata.dead (gp_color (i), dame (0, i)) + np (i);
155 end;
156 end;
157
158
159 add_dame: proc (g);
160
161 dcl g fixed bin;
162
163 dame (board (i, j), g) = dame (board (i, j), g) + 1;
164 if board (i, j) = 0 then
165 if dami1 (g) = 0 then do;
166 dami1 (g) = i;
167 damj1 (g) = j;
168 end;
169 else do;
170 dami2 (g) = i;
171 damj2 (g) = j;
172 end;
173
174 end add_dame;
175
176 end cap;