PINPANPO.inc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. procedure game(flag : byte; var x,y : byte);far;
  2. var
  3. waitesplay : array [1..n*n] of integer;
  4. waitesenemy : array[1..n*n] of integer;
  5. maxwaitpl,maxpl,maxen : integer;
  6. maxwaiten : integer;
  7. i,x1,y1,pl,en : integer;
  8. {==============================================} {x v pole}
  9. function coordx(k : byte) : byte;
  10. begin
  11. if k mod n = 0 then
  12. coordx := n
  13. else
  14. coordx := k mod n;
  15. end;
  16. {=============================================}
  17. {==============================================} {y v pole}
  18. function coordy(k : byte) : byte;
  19. begin
  20. if k mod n = 0 then
  21. coordy := k div n
  22. else
  23. coordy := k div n +1
  24. end;
  25. {=============================================}
  26. {!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  27. {==============================================} {schitibaet massiv po diagonali}
  28. procedure getmasrow (var mas:mo2; k:byte; pol:mo);
  29. var
  30. l,i,j : integer;
  31. begin
  32. j := coordy(k);
  33. l := coordx(k);
  34. for i := l-4 to l+4 do
  35. begin
  36. if (i < 1)or (i>n) then
  37. mas[i-l+5]:=3
  38. else
  39. mas[i-l+5]:= pol[j,i]; {!@!!@@$#@$##$%#%^$%^$%^$%^$^}
  40. end;
  41. end;
  42. {=============================================}
  43. {==============================================} {schitibaet massiv po verticali}
  44. procedure getmasst (var mas: mo2;k:byte;pol: mo);
  45. var
  46. l,i,j : integer;
  47. begin
  48. l := coordy(k);
  49. j := coordx(k);
  50. for i := l-4 to l+4 do
  51. begin
  52. if (i<1) or (i>n) then
  53. mas[i-l+5] := 3
  54. else
  55. mas[i-l+5]:=pol[i,j];
  56. end;
  57. end;
  58. {=============================================}
  59. {==============================================} {schitibaet massiv po naclonnnoy c left to right}
  60. procedure getmasleftn (var mas: mo2;k:byte;pol: mo);
  61. var
  62. l,i,j,h,f : integer;
  63. begin
  64. f := 1;
  65. h := coordy(k);
  66. l := coordx(k);
  67. j := h-4;
  68. for i := l-4 to l+4 do
  69. begin
  70. if (i<1)or (i>n)or(j<1)or(j>n) then
  71. begin
  72. mas[f]:=3;
  73. inc(f);
  74. end
  75. else
  76. begin
  77. mas[f] := pol[j,i];
  78. inc(f);
  79. end;
  80. inc(j);
  81. end;
  82. end;
  83. {=============================================}
  84. {=============================================} {schitibaet massiv po naclonnoy c right to left}
  85. procedure getmasrightn (var mas: mo2;k:byte;pol :mo);
  86. var
  87. l,i,j,h,r,f : integer;
  88. begin
  89. f := 1;
  90. h := coordy(k);
  91. l := coordx(k);
  92. j := h-4;
  93. for i := l+4 downto l-4 do
  94. begin
  95. if (i<1)or (i>n)or(j<1)or(j>n) then
  96. begin
  97. mas[f]:=3;
  98. inc(f);
  99. end
  100. else
  101. begin
  102. mas[f] := pol[j,i];
  103. inc(f);
  104. end;
  105. inc(j);
  106. end;
  107. end;
  108. {=============================================}
  109. {!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  110. {==============================================} {osnovnoy prov!!!!!!}
  111. function analis (play: byte; k: byte; pol: mo):byte ;
  112. var
  113. mas:mo2;
  114. weight1 :array[1..4] of byte;
  115. maxweight,i : byte;
  116. {------------------------------------------------------}
  117. function analis9 (play:byte;pol: mo;mas:mo2): byte ;
  118. var
  119. i,right,left,nx,l,r,max : integer;
  120. wait6 :array[1..4] of byte;
  121. {------------------------------------------------------}
  122. function analis6(left:integer;mas : mo2;play : byte) : byte;
  123. var
  124. i,nz,nzz,nzx,nxx,nx,nzzxx,nx1 :integer;
  125. begin
  126. nx:=0;
  127. nz:=0;
  128. for i := l to l+5 do
  129. if mas[i] = 0 then
  130. begin
  131. inc(nz);
  132. if nzz < nz then
  133. nzz:=nz;
  134. if nxx >0 then
  135. inc(nzx);
  136. nx := 0;
  137. end
  138. else
  139. begin
  140. inc(nx1);
  141. inc(nx);
  142. if nxx<nx then
  143. nxx:=nx;
  144. nz :=0;
  145. nzzxx:=nzx;
  146. end;
  147. case nxx of
  148. 5 : analis6 :=99; {-xxxxx}
  149. 4 : begin if nzz = 1 then analis6 :=96 {-xxxx-}
  150. else analis6 :=87; {xxxx--}
  151. if nx1 = 5 then analis6 :=93;{xxxx-x}
  152. end;
  153. 3 : begin case nx1 of
  154. 5 : analis6 := 91; {xxx-xx}
  155. 4 : if nzz=1 then analis6 := 91{xxx-x-}
  156. else analis6 :=76; {xxx--x}
  157. 3 : if nzz = 2 then analis6 := 90 {-xxx--}
  158. else analis6 := 50;{xxx---}
  159. end;
  160. end;
  161. 2 : begin case nx1 of
  162. 4 : if nzz=1 then analis6:=78 {xx-x-x}
  163. else analis6 :=60; {xx--xx}
  164. 3 : begin case nzz of
  165. 1 : analis6 :=60; {-xx-x-}
  166. 2 : if nzzxx =1 then analis6:=50 {xx-x--}
  167. else analis6 :=51;{xx--xx-}
  168. 3 : analis6 := 40; {xx---x}
  169. end
  170. end;
  171. 2 : if (nzz=2)and(nzz=3) then analis6 := 20 {--xx-- -xx---}
  172. else analis6 := 15; {xx----}
  173. end
  174. end;
  175. 1 : begin case nx1 of
  176. 3 : analis6 := 30; {x-x-x-}
  177. 2 : analis6 := 9;
  178. 1 : if nzz < 5 then analis6 := 5 {-x-}
  179. else analis6 := 1; {x-----}
  180. end
  181. end
  182. end;
  183. end;
  184. {------------------------------------------------------}
  185. begin
  186. nx := 0;
  187. for i := 6 to 9 do
  188. if (mas[i] <> play)and(mas[i]<>0) then
  189. begin
  190. right := i-1;
  191. break;
  192. end
  193. else right := i;
  194. for i :=4 downto 1 do
  195. if (mas[i] <> play)and(mas[i]<>0) then
  196. begin
  197. left := i+1;
  198. break;
  199. end
  200. else left := i;
  201. if (right-left)<= 3 then
  202. begin
  203. analis9 := 0;
  204. exit;
  205. end
  206. else
  207. begin
  208. if right-left = 4 then
  209. begin
  210. for i := left to right do
  211. if mas[i] = play then inc(nx);
  212. case nx of
  213. 5 : analis9 :=99;
  214. 4 : analis9 :=80;
  215. 3 : analis9 :=30;
  216. 2 : analis9 :=15;
  217. 1 : analis9 := 7;
  218. end;
  219. exit;
  220. end
  221. else
  222. begin
  223. l :=left;
  224. for i:=l to(right-left)-4 do
  225. begin
  226. wait6[i-l+1] := analis6(l,mas,play);
  227. inc(l);
  228. end;
  229. max := mas[1];
  230. for i :=2 to 4 do
  231. if wait6[i] > wait6[max] then
  232. max:= i;
  233. analis9 := wait6[max];
  234. end;
  235. end;
  236. end;
  237. {-------------------------------------------------}
  238. begin
  239. getmasrow (mas,k,pol);
  240. weight1[1] := analis9 (play,pol,mas);
  241. getmasst (mas,k,pol);
  242. weight1[2] := analis9 (play,pol,mas);
  243. getmasrightn (mas,k,pol);
  244. weight1[3] := analis9 (play,pol,mas);
  245. getmasleftn (mas,k,pol);
  246. weight1[4]:= analis9 (play,pol,mas);
  247. maxweight := weight1[1];
  248. for i := 2 to 4 do
  249. if weight1[i]>maxweight then
  250. maxweight := weight1[i];
  251. analis :=maxweight;
  252. end;
  253. {=============================================}
  254. begin
  255. fillchar(waitesplay,n*n,0);
  256. fillchar(waitesenemy,n*n,0);
  257. if flag = 1 then
  258. begin
  259. pl := 1;
  260. en := 2;
  261. end
  262. else
  263. begin
  264. pl :=2;
  265. en :=1;
  266. end;
  267. for i :=1 to n*n do
  268. begin
  269. x1:= coordx(i);
  270. y1 := coordy(i);
  271. if pole[y1,x1] = 0 then
  272. begin
  273. pole[y1,x1]:=pl;
  274. waitesplay[i]:=analis(pl,i,pole);
  275. pole[y1,x1]:=en;
  276. waitesenemy[i] := analis(en,i,pole);
  277. pole[y1,x1]:=0;
  278. end
  279. else
  280. begin
  281. waitesplay[i]:=-1;
  282. waitesenemy[i] :=-1;
  283. end
  284. end;
  285. maxwaitpl := waitesplay[1];
  286. maxwaiten := waitesenemy[1];
  287. maxpl := 1;
  288. maxen := 1;
  289. for i := 2 to n*n do
  290. begin
  291. if maxwaitpl < waitesplay[i] then
  292. begin
  293. maxwaitpl := waitesplay[i];
  294. maxpl := i;
  295. end;
  296. if maxwaiten < waitesenemy[i] then
  297. begin
  298. maxwaiten := waitesenemy[i];
  299. maxen := i;
  300. end;
  301. end;
  302. if maxwaitpl >= maxwaiten then
  303. begin
  304. x := coordx(maxpl);
  305. y := coordy(maxpl);
  306. end
  307. else
  308. begin
  309. x := coordx(maxen);
  310. y := coordy(maxen);
  311. end;
  312. end;