Use this to learn the idea, then write your own version.
12345678 9var b : array 1 .. 8, 1 .. 8 of int10var config : string11var n, row, col : int12var player : string := "b"13var countb, countw : int14var f : string (1)15 1617procedure print18 for r : 1 .. 819 for c : 1 .. 820 if b (r, c) = 0 then21 put " " ..22 elsif b (r, c) = 1 then23 put "w" ..24 else25 put "b" ..26 end if27 end for28 put ""29 end for30end print31 32333435procedure reverse (r, c : int)36 var i, j, k : int37 var found : boolean38 if b (r, c) = 1 then39 k := 240 else41 k := 142 end if43 44 45 i := r - 146 found := false47 loop48 exit when i = 0 or found or b (i, c) = 049 if b (i, c) = b (r, c) then50 found := true51 end if52 i := i - 153 end loop54 if found then55 i := r - 156 loop57 exit when b (i, c) = b (r, c)58 b (i, c) := b (r, c)59 i := i - 160 end loop61 end if62 63 64 i := r + 165 found := false66 loop67 exit when i = 9 or found or b (i, c) = 068 if b (i, c) = b (r, c) then69 found := true70 end if71 i := i + 172 end loop73 if found then74 i := r + 175 loop76 exit when b (i, c) = b (r, c)77 b (i, c) := b (r, c)78 i := i + 179 end loop80 end if81 82 83 i := c - 184 found := false85 loop86 exit when i = 0 or found or b (r, i) = 087 if b (r, i) = b (r, c) then88 found := true89 end if90 i := i - 191 end loop92 if found then93 i := c - 194 loop95 exit when b (r, i) = b (r, c)96 b (r, i) := b (r, c)97 i := i - 198 end loop99 end if100 101 102 i := c + 1103 found := false104 loop105 exit when i = 9 or found or b (r, i) = 0106 if b (r, i) = b (r, c) then107 found := true108 end if109 i := i + 1110 end loop111 if found then112 i := c + 1113 loop114 exit when b (r, i) = b (r, c)115 b (r, i) := b (r, c)116 i := i + 1117 end loop118 end if119 120 121 i := r - 1122 j := c - 1123 found := false124 loop125 exit when i = 0 or j = 0 or found or b (i, j) = 0126 if b (i, j) = b (r, c) then127 found := true128 end if129 i := i - 1130 j := j - 1131 end loop132 if found then133 i := r - 1134 j := c - 1135 loop136 exit when b (i, j) = b (r, c)137 b (i, j) := b (r, c)138 i := i - 1139 j := j - 1140 end loop141 end if142 143 144 i := r - 1145 j := c + 1146 found := false147 loop148 exit when i = 0 or j = 9 or found or b (i, j) = 0149 if b (i, j) = b (r, c) then150 found := true151 end if152 i := i - 1153 j := j + 1154 end loop155 if found then156 i := r - 1157 j := c + 1158 loop159 exit when b (i, j) = b (r, c)160 b (i, j) := b (r, c)161 i := i - 1162 j := j + 1163 end loop164 end if165 166 167 i := r + 1168 j := c - 1169 found := false170 loop171 exit when i = 9 or j = 0 or found or b (i, j) = 0172 if b (i, j) = b (r, c) then173 found := true174 end if175 i := i + 1176 j := j - 1177 end loop178 if found then179 i := r + 1180 j := c - 1181 loop182 exit when b (i, j) = b (r, c)183 b (i, j) := b (r, c)184 i := i + 1185 j := j - 1186 end loop187 end if188 189 190 i := r + 1191 j := c + 1192 found := false193 loop194 exit when i = 9 or j = 9 or found or b (i, j) = 0195 if b (i, j) = b (r, c) then196 found := true197 end if198 i := i + 1199 j := j + 1200 end loop201 if found then202 i := r + 1203 j := c + 1204 loop205 exit when b (i, j) = b (r, c)206 b (i, j) := b (r, c)207 i := i + 1208 j := j + 1209 end loop210 end if211end reverse212 213214for r : 1 .. 8215 for c : 1 .. 8216 b (r, c) := 0217 end for218end for219get config220if config = "a" then221 b (4, 4) := 1222 b (5, 5) := 1223 b (4, 5) := 2224 b (5, 4) := 2225elsif config = "b" then226 for r : 1 .. 8227 b (r, r) := 2228 b (r, 9 - r) := 1229 end for230elsif config = "c" then231 for r : 1 .. 8232 b (r, 3) := 2233 b (r, 4) := 2234 b (r, 5) := 1235 b (r, 6) := 1236 end for237end if238 239240get n241for i : 1 .. n242 get row, col 243 if player = "b" then244 b (row, col) := 2245 player := "w"246 else247 b (row, col) := 1248 player := "b"249 end if250 reverse (row, col)251end for252 253254countb := 0255countw := 0256for r : 1 .. 8257 for c : 1 .. 8258 if b (r, c) = 1 then259 countw := countw + 1260 elsif b (r, c) = 2 then261 countb := countb + 1262 end if263 end for264end for265put countb, " ", countw266 267 268 269