Rod2.inc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. Procedure RodOldTurn(cz:byte; var x,y : byte);far;
  2. Var
  3. x1,y1,PR,i,max,MAXX,MAXY,MAXI,MAXprX,MAXprY,MAXprI: byte;
  4. maxp,maxprp : integer;
  5. ar : array [1..20] of byte;
  6. apr : array [1..20] of byte;
  7. found,tmp,tmpPR,FoundPR,KON : boolean;
  8. Procedure FindY(x1,y1,d:byte);
  9. begin
  10. case d of
  11. 5: if (pole[x1,y1-1]=0) then begin x:=x1;y:=y1-1 end else
  12. if (pole[x1,y1-2]=0) then begin x:=x1;y:=y1-2 end else
  13. if (pole[x1,y1-3]=0) then begin x:=x1;y:=y1-3 end else
  14. begin x:=x1;y:=y1-4 end;
  15. 4: if (pole[x1,y1-1]=0) then begin x:=x1;y:=y1-1 end else
  16. if (pole[x1,y1+1]=0) then begin x:=x1;y:=y1+1 end else
  17. if (pole[x1,y1-2]=0) then begin x:=x1;y:=y1-2 end else
  18. begin x:=x1;y:=y1-3 end;
  19. 3: if (pole[x1,y1-1]=0) then begin x:=x1;y:=y1-1 end else
  20. if (pole[x1,y1+1]=0) then begin x:=x1;y:=y1+1 end else
  21. if (pole[x1,y1-2]=0) then begin x:=x1;y:=y1-2 end else
  22. begin x:=x1;y:=y1+2 end;
  23. 2: if (pole[x1,y1-1]=0) then begin x:=x1;y:=y1-1 end else
  24. if (pole[x1,y1+1]=0) then begin x:=x1;y:=y1+1 end else
  25. if (pole[x1,y1+2]=0) then begin x:=x1;y:=y1+2 end else
  26. begin x:=x1;y:=y1+3 end;
  27. 1: if (pole[x1,y1+1]=0) then begin x:=x1;y:=y1+1 end else
  28. if (pole[x1,y1+2]=0) then begin x:=x1;y:=y1+2 end else
  29. if (pole[x1,y1+3]=0) then begin x:=x1;y:=y1+3 end else
  30. begin x:=x1;y:=y1+4 end;
  31. end;
  32. end;
  33. Procedure FindX(x1,y1,d:byte);
  34. begin
  35. case d of
  36. 5: if (pole[x1-1,y1]=0) then begin x:=x1-1;y:=y1 end else
  37. if (pole[x1-2,y1]=0) then begin x:=x1-2;y:=y1 end else
  38. if (pole[x1-3,y1]=0) then begin x:=x1-3;y:=y1 end else
  39. begin x:=x1-4;y:=y1-4 end;
  40. 4: if (pole[x1-1,y1]=0) then begin x:=x1-1;y:=y1 end else
  41. if (pole[x1+1,y1]=0) then begin x:=x1+1;y:=y1 end else
  42. if (pole[x1-2,y1]=0) then begin x:=x1-2;y:=y1 end else
  43. begin x:=x1-3;y:=y1 end;
  44. 3: if (pole[x1-1,y1]=0) then begin x:=x1-1;y:=y1 end else
  45. if (pole[x1+1,y1]=0) then begin x:=x1+1;y:=y1 end else
  46. if (pole[x1-2,y1]=0) then begin x:=x1-2;y:=y1 end else
  47. begin x:=x1+2;y:=y1 end;
  48. 2: if (pole[x1-1,y1]=0) then begin x:=x1-1;y:=y1 end else
  49. if (pole[x1+1,y1]=0) then begin x:=x1+1;y:=y1 end else
  50. if (pole[x1+2,y1]=0) then begin x:=x1+2;y:=y1 end else
  51. begin x:=x1+3;y:=y1 end;
  52. 1: if (pole[x1+1,y1]=0) then begin x:=x1+1;y:=y1 end else
  53. if (pole[x1+2,y1]=0) then begin x:=x1+2;y:=y1 end else
  54. if (pole[x1+3,y1]=0) then begin x:=x1+3;y:=y1 end else
  55. begin x:=x1+4;y:=y1 end;
  56. end;
  57. end;
  58. Procedure FindYX(x1,y1,d:byte);
  59. begin
  60. case d of
  61. 5: if (pole[x1-1,y1-1]=0) then begin x:=x1-1;y:=y1-1 end else
  62. if (pole[x1-2,y1-2]=0) then begin x:=x1-2;y:=y1-2 end else
  63. if (pole[x1-3,y1-3]=0) then begin x:=x1-3;y:=y1-3 end else
  64. begin x:=x1-4;y:=y1-4 end;
  65. 4: if (pole[x1-1,y1-1]=0) then begin x:=x1-1;y:=y1-1 end else
  66. if (pole[x1+1,y1+1]=0) then begin x:=x1+1;y:=y1+1 end else
  67. if (pole[x1-2,y1-2]=0) then begin x:=x1-2;y:=y1-2 end else
  68. begin x:=x1-3;y:=y1-3 end;
  69. 3: if (pole[x1-1,y1-1]=0) then begin x:=x1-1;y:=y1-1 end else
  70. if (pole[x1+1,y1+1]=0) then begin x:=x1+1;y:=y1+1 end else
  71. if (pole[x1-2,y1-2]=0) then begin x:=x1-2;y:=y1-2 end else
  72. begin x:=x1+2;y:=y1+2 end;
  73. 2: if (pole[x1-1,y1-1]=0) then begin x:=x1-1;y:=y1-1 end else
  74. if (pole[x1+1,y1+1]=0) then begin x:=x1+1;y:=y1+1 end else
  75. if (pole[x1+2,y1+2]=0) then begin x:=x1+2;y:=y1+2 end else
  76. begin x:=x1+3;y:=y1+3 end;
  77. 1: if (pole[x1+1,y1+1]=0) then begin x:=x1+1;y:=y1+1 end else
  78. if (pole[x1+2,y1+2]=0) then begin x:=x1+2;y:=y1+2 end else
  79. if (pole[x1+3,y1+3]=0) then begin x:=x1+3;y:=y1+3 end else
  80. begin x:=x1+4;y:=y1+4 end;
  81. end;
  82. end;
  83. Procedure Find_YX(x1,y1,d:byte);
  84. begin
  85. case d of
  86. 5: if (pole[x1+1,y1-1]=0) then begin x:=x1+1;y:=y1-1 end else
  87. if (pole[x1+2,y1-2]=0) then begin x:=x1+2;y:=y1-2 end else
  88. if (pole[x1+3,y1-3]=0) then begin x:=x1+3;y:=y1-3 end else
  89. begin x:=x1+4;y:=y1-4 end;
  90. 4: if (pole[x1+1,y1-1]=0) then begin x:=x1+1;y:=y1-1 end else
  91. if (pole[x1-1,y1+1]=0) then begin x:=x1-1;y:=y1+1 end else
  92. if (pole[x1+2,y1-2]=0) then begin x:=x1+2;y:=y1-2 end else
  93. begin x:=x1+3;y:=y1-3 end;
  94. 3: if (pole[x1+1,y1-1]=0) then begin x:=x1+1;y:=y1-1 end else
  95. if (pole[x1-1,y1+1]=0) then begin x:=x1-1;y:=y1+1 end else
  96. if (pole[x1+2,y1-2]=0) then begin x:=x1+2;y:=y1-2 end else
  97. begin x:=x1-2;y:=y1+2 end;
  98. 2: if (pole[x1+1,y1-1]=0) then begin x:=x1+1;y:=y1-1 end else
  99. if (pole[x1-1,y1+1]=0) then begin x:=x1-1;y:=y1+1 end else
  100. if (pole[x1-2,y1+2]=0) then begin x:=x1-2;y:=y1+2 end else
  101. begin x:=x1-3;y:=y1+3 end;
  102. 1: if (pole[x1-1,y1+1]=0) then begin x:=x1-1;y:=y1+1 end else
  103. if (pole[x1-2,y1+2]=0) then begin x:=x1-2;y:=y1+2 end else
  104. if (pole[x1-3,y1+3]=0) then begin x:=x1-3;y:=y1+3 end else
  105. begin x:=x1-4;y:=y1+4 end;
  106. end;
  107. end;
  108. Procedure AnalY(x1,y1:byte;c:boolean);
  109. var pr,cz1,j,i : byte;
  110. begin
  111. if c then cz1 := cz else cz1:=3-cz;
  112. if c then pr := 3-cz else pr := cz;
  113. for i := 5 downto 1 do
  114. if (pole[x1,y1-i+1]<>pr) and
  115. (pole[x1,y1-i+2]<>pr) and
  116. (pole[x1,y1-i+3]<>pr) and (y1-i+1>0) and (y1+5-i<n+1) and
  117. (pole[x1,y1-i+4]<>pr) and
  118. (pole[x1,y1-i+5]<>pr) then
  119. begin
  120. tmp := true;
  121. for j := 1 to 5 do if pole[x1,y1-i+j] = cz1 then
  122. if c then inc(ar[i]) else inc(aPr[i]);
  123. end;
  124. end;
  125. Procedure AnalX(x1,y1:byte;c:boolean);
  126. var pr,cz1,j,i : byte;
  127. begin
  128. if c then cz1 := cz else cz1:=3-cz;
  129. if c then pr := 3-cz else pr := cz;
  130. for i := 5 downto 1 do
  131. if (pole[x1-i+1,y1]<>pr) and
  132. (pole[x1-i+2,y1]<>pr) and
  133. (pole[x1-i+3,y1]<>pr) and (x1-i+1>0) and (x1+5-i<n+1) and
  134. (pole[x1-i+4,y1]<>pr) and
  135. (pole[x1-i+5,y1]<>pr) then
  136. begin
  137. tmp := true;
  138. for j := 1 to 5 do if pole[x1-i+j,y1] = cz1 then
  139. if c then inc(ar[5+i]) else inc(aPr[5+i]);
  140. end;
  141. end;
  142. Procedure AnalYX(x1,y1:byte;c:boolean);
  143. var pr,cz1,j,i : byte;
  144. begin
  145. if c then cz1 := cz else cz1:=3-cz;
  146. if c then pr := 3-cz else pr := cz;
  147. for i := 5 downto 1 do
  148. if (pole[x1-i+1,y1-i+1]<>pr) and
  149. (pole[x1-i+2,y1-i+2]<>pr) and
  150. (pole[x1-i+3,y1-i+3]<>pr) and (x1-i+1>0) and (x1+5-i<n+1) and
  151. (pole[x1-i+4,y1-i+4]<>pr) and (y1-i+1>0) and (y1+5-i<n+1) and
  152. (pole[x1-i+5,y1-i+5]<>pr) then
  153. begin
  154. tmp := true;
  155. for j := 1 to 5 do if pole[x1-i+j,y1-i+j] = cz1 then
  156. if c then inc(ar[10+i]) else inc(aPr[10+i]);
  157. end;
  158. end;
  159. Procedure Anal_YX(x1,y1:byte;c:boolean);
  160. var pr,cz1,j,i : byte;
  161. begin
  162. if c then cz1 := cz else cz1:=3-cz;
  163. if c then pr := 3-cz else pr := cz;
  164. for i := 5 downto 1 do
  165. if (pole[x1+i-1,y1-i+1]<>pr) and
  166. (pole[x1+i-2,y1-i+2]<>pr) and
  167. (pole[x1+i-3,y1-i+3]<>pr) and (x1+i-1<n+1) and (x1-5+i>0) and
  168. (pole[x1+i-4,y1-i+4]<>pr) and (y1-i+1>0) and (y1+5-i<n+1) and
  169. (pole[x1+i-5,y1-i+5]<>pr) then
  170. begin
  171. tmp := true;
  172. for j := 1 to 5 do if pole[x1+i-j,y1-i+j] = cz1 then
  173. if c then inc(ar[15+i]) else inc(aPr[15+i]);
  174. end;
  175. end;
  176. Begin
  177. randomize;
  178. pr := 3 - cz;
  179. found := false;
  180. for i := 1 to 20 do ar[i] := 0;
  181. for i := 1 to 20 do apr[i] := 0;
  182. FoundPR := false;
  183. MAXP := 0;
  184. MAXprP := 0;
  185. KON := false;
  186. for y1 := 1 to n do
  187. for x1 := 1 to n do
  188. if Pole[x1,y1] = cz then
  189. begin
  190. if not kon then begin
  191. tmp := false;
  192. AnalX(x1,y1,true);
  193. AnalY(x1,y1,true);
  194. AnalYX(x1,y1,true);
  195. Anal_YX(x1,y1,true);
  196. if tmp then
  197. begin
  198. max := 1;
  199. for i := 2 to 20 do if ar[i] > ar[max] then max := i;
  200. if ar[max] > MAXP then
  201. begin
  202. MAXP := ar[max];
  203. MAXI := max;
  204. MAXX := x1;
  205. MAXY := y1;
  206. if maxp > 3 then begin KON := true; FoundPr := false; end;
  207. found := true;
  208. end;
  209. for i := 1 to 20 do ar[i] := 0;
  210. end;
  211. end;
  212. end else if pole[x1,y1] = PR then if not foundPR then
  213. begin
  214. if not kon then begin
  215. tmp := false;
  216. AnalX(x1,y1,false);
  217. AnalY(x1,y1,false);
  218. AnalYX(x1,y1,false);
  219. Anal_YX(x1,y1,false);
  220. if tmp then
  221. begin
  222. max := 0;
  223. for i := 1 to 20 do if apr[i] > 2 then max := i;
  224. if max <> 0 then
  225. if apr[max] > MAXprP then
  226. begin
  227. MAXprP := apr[max];
  228. MAXprI := max;
  229. MAXprX := x1;
  230. MAXprY := y1;
  231. foundPR := true;
  232. Found := true;
  233. end;
  234. for i := 1 to 20 do apr[i] := 0;
  235. end;
  236. end;
  237. end;
  238. if not found then
  239. repeat
  240. x:=random(n)+1;
  241. y:=random(n)+1;
  242. until Pole[x,y] = 0
  243. else if foundPR then
  244. begin
  245. if (maxprI in [1..5]) then FindY(maxprx,maxpry,maxprI) else
  246. if (maxprI in [6..10]) then FindX(maxprx,maxpry,maxprI-5) else
  247. if (maxprI in [11..15]) then FindYX(maxprx,maxpry,maxprI-10) else
  248. if (maxprI in [16..20]) then Find_YX(maxprx,maxpry,maxprI-15)
  249. end
  250. else
  251. if (maxI<6) then FindY(MAXx,MAXy,maxI) else
  252. if (maxI in [6..10]) then FindX(MAXx,MAXy,maxI-5) else
  253. if (maxI in [11..15]) then FindYX(MAXx,MAXy,maxI-10) else
  254. Find_YX(MAXx,MAXy,maxI-15);
  255. End;