Advertisement
Guest User

Untitled

a guest
May 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp11
  8. {
  9. class Node
  10. {
  11. public char[][] polegry;
  12. public List<Node> children;
  13.  
  14. public Node(char[][] value)
  15. {
  16. polegry = value;
  17. children = null;
  18. }
  19.  
  20. public bool isLeaf(ref Node node)
  21. {
  22. return(children == null);
  23. }
  24.  
  25. public void insertData(ref Node node, char[][] data)
  26. {
  27. if (node == null)
  28. {
  29. node = new Node(data);
  30.  
  31. }
  32. else children.Add(new Node(data));
  33. }
  34.  
  35. public bool search(Node node, char[][] s)
  36. {
  37. if (node == null) return false;
  38. if (node.polegry == s)
  39. {
  40. return true;
  41. }
  42. else
  43. {
  44. foreach (Node element in children)
  45. {
  46. if (node.search(element, s)) return true;
  47. }
  48. return false;
  49. }
  50. }
  51.  
  52. public void display(Node n)
  53. {
  54. if (n == null) return;
  55.  
  56. foreach (Node element in children)
  57. {
  58. for (int i = 0; i < 10; i++)
  59. {
  60. for (int k = 0; k < 10; k++)
  61. {
  62. Console.Write(polegry[i][k]);
  63. }
  64. Console.Write("\n");
  65. }
  66. }
  67. }
  68.  
  69. }
  70. class BinaryTree
  71. {
  72. private Node root;
  73. private int count;
  74.  
  75. public BinaryTree()
  76. {
  77. root = null;
  78. count = 0;
  79. }
  80. public bool isEmpty()
  81. {
  82. return root == null;
  83. }
  84.  
  85. public void insert(char[][] d)
  86. {
  87. if (isEmpty())
  88. {
  89. root = new Node(d);
  90. }
  91. else
  92. {
  93. root.insertData(ref root, d);
  94. }
  95.  
  96. count++;
  97. }
  98.  
  99. public bool search(char[][] s)
  100. {
  101. return root.search(root, s);
  102. }
  103.  
  104. public bool isLeaf()
  105. {
  106. if (!isEmpty())
  107. return root.isLeaf(ref root);
  108.  
  109. return true;
  110. }
  111.  
  112. public void display()
  113. {
  114. if (!isEmpty())root.display(root);
  115. }
  116.  
  117. public int Count()
  118. {
  119. return count;
  120. }
  121. }
  122. class Program
  123. {
  124.  
  125. static char[][] polegry;
  126. static int ROW = 10;
  127. static int COL = 10;
  128. static int min(int a, int b)
  129. {
  130. if (a < b) return a;
  131. else return b;
  132.  
  133. }
  134. static int max(int a, int b)
  135. {
  136. if (a > b) return a;
  137. else return b;
  138.  
  139. }
  140. static bool isGameOver(char[][] polegry)
  141. {
  142. for (int i = 0; i < 10; i++)
  143. {
  144. for (int k = 0; k < 10; k++)
  145. {
  146. if (polegry[i][k] == 0) return false;
  147. }
  148. }
  149. return true;
  150. }
  151. static int[] evaluateBoard(char[][] polegry)
  152. {
  153. int[] tab = new int[2];
  154. tab[0] = policzbiale(polegry);
  155. tab[1] = policzczarne(polegry);
  156. return tab;
  157. }
  158. static int minimax(Node node, int depth, bool maximizingPlayer)
  159. {
  160. if (depth == 0 || isGameOver(node.polegry))
  161. {
  162. int[] tab = new int[2];
  163. tab = evaluateBoard(node.polegry);
  164. return tab[0]+ (-1)*tab[1];
  165. }
  166. if (maximizingPlayer)
  167. {
  168. int value = -9999;
  169. foreach (Node element in node.children)
  170. {
  171. value = max(value, minimax(element, depth - 1, false));
  172. }
  173. return value;
  174. }
  175. else
  176. {
  177. int value = 9999;
  178. foreach (Node element in node.children)
  179. {
  180. value = min(value, minimax(element, depth - 1, true));
  181. }
  182. return value;
  183. }
  184. }
  185. static void wypisz(char[][] polegry)
  186. {
  187. for (int i = 0; i < ROW; i++)
  188. {
  189. Console.WriteLine(polegry[i]);
  190. }
  191. }
  192. static int policzbiale(char[][] polegry)
  193. {
  194. int wynik = 0;
  195. for (int i = 0; i < 10; i++)
  196. {
  197. String napis = String.Empty;
  198. for (int k = 0; k < 10; k++) napis += polegry[i][k];
  199. while (napis.Contains("1111"))
  200. {
  201. napis = napis.Remove(napis.IndexOf("1111"),4);
  202. wynik++;
  203. }
  204. }
  205. for (int i = 0; i < 10; i++)
  206. {
  207. String napis2 = String.Empty;
  208. for (int k = 0; k < 10; k++) napis2 += polegry[k][i];
  209. while (napis2.Contains("1111"))
  210. {
  211. napis2 = napis2.Remove(napis2.IndexOf("1111"), 4);
  212. wynik++;
  213. }
  214.  
  215. }
  216. for (int line = 1; line <= (ROW + COL - 1); line++)
  217. {
  218. String napis5 = String.Empty;
  219. int start_col = Math.Max(0, line - ROW);
  220. int count = Math.Min(line, Math.Min((COL - start_col), ROW));
  221. for (int j = 0; j < count; j++) napis5 += polegry[Math.Min(ROW, line) - j - 1][start_col + j];
  222. while (napis5.Contains("1111"))
  223. {
  224. napis5 = napis5.Remove(napis5.IndexOf("1111"), 4);
  225. wynik++;
  226. }
  227. }
  228. char[][] invpolegry = new char[10][];
  229. for (int i = 0; i < 10; i++)
  230. {
  231. invpolegry[i] = new char[10];
  232. }
  233. for (int i = 0; i < 10; i++)
  234. {
  235. for (int j = 0; j < 10; j++)
  236. {
  237. invpolegry[i][j] = polegry[i][9 - j];
  238. }
  239.  
  240. }
  241. for (int line = 1; line <= (ROW + COL - 1); line++)
  242. {
  243. String napis6 = String.Empty;
  244. int start_col = Math.Max(0, line - ROW);
  245. int count = Math.Min(line, Math.Min((COL - start_col), ROW));
  246. for (int j = 0; j < count; j++) napis6 += invpolegry[Math.Min(ROW, line) - j - 1][start_col + j];
  247. while (napis6.Contains("1111"))
  248. {
  249. napis6 = napis6.Remove(napis6.IndexOf("1111"), 4);
  250. wynik++;
  251. }
  252. }
  253.  
  254. return wynik;
  255. }
  256. static int policzczarne(char[][] polegry)
  257. {
  258. int wynik = 0;
  259. for (int i = 0; i < 10; i++)
  260. {
  261. String napis = String.Empty;
  262. for (int k = 0; k < 10; k++) napis += polegry[i][k];
  263. while (napis.Contains("2222"))
  264. {
  265. napis = napis.Remove(napis.IndexOf("2222"), 4);
  266. wynik++;
  267. }
  268. }
  269. for (int i = 0; i < 10; i++)
  270. {
  271. String napis2 = String.Empty;
  272. for (int k = 0; k < 10; k++) napis2 += polegry[k][i];
  273. while (napis2.Contains("2222"))
  274. {
  275. napis2 = napis2.Remove(napis2.IndexOf("2222"), 4);
  276. wynik++;
  277. }
  278. }
  279. for (int line = 1; line <= (ROW + COL - 1); line++)
  280. {
  281. String napis5 = String.Empty;
  282. int start_col = Math.Max(0, line - ROW);
  283. int count = Math.Min(line, Math.Min((COL - start_col), ROW));
  284. for (int j = 0; j < count; j++) napis5 += polegry[Math.Min(ROW, line) - j - 1][start_col + j];
  285. while (napis5.Contains("2222"))
  286. {
  287. napis5 = napis5.Remove(napis5.IndexOf("2222"), 4);
  288. wynik++;
  289. }
  290. }
  291. char[][] invpolegry = new char[10][];
  292. for (int i = 0; i < 10; i++)
  293. {
  294. invpolegry[i] = new char[10];
  295. }
  296. for (int i = 0; i < 10; i++)
  297. {
  298. for (int j = 0; j < 10; j++)
  299. {
  300. invpolegry[i][j] = polegry[i][9 - j];
  301. }
  302.  
  303. }
  304. for (int line = 1; line <= (ROW + COL - 1); line++)
  305. {
  306. String napis6 = String.Empty;
  307. int start_col = Math.Max(0, line - ROW);
  308. int count = Math.Min(line, Math.Min((COL - start_col), ROW));
  309. for (int j = 0; j < count; j++) napis6 += invpolegry[Math.Min(ROW, line) - j - 1][start_col + j];
  310. while (napis6.Contains("2222"))
  311. {
  312. napis6 = napis6.Remove(napis6.IndexOf("2222"), 4);
  313. wynik++;
  314. }
  315. }
  316.  
  317. return wynik;
  318. }
  319. static void Main(string[] args)
  320. {
  321. polegry = new char[10][];
  322. for (int i = 0; i < 10; i++)
  323. {
  324. polegry[i] = new char[10];
  325.  
  326. }
  327. for (int i = 0; i < 10; i++)
  328. {
  329. for (int j = 0; j < 10; j++)
  330. {
  331. polegry[i][j] = '0';
  332. }
  333. }
  334. polegry[0] = "0000000000".ToCharArray();
  335. polegry[1] = "2222122220".ToCharArray();
  336. polegry[2] = "1111011110".ToCharArray();
  337. polegry[3] = "0002000000".ToCharArray();
  338. polegry[4] = "0000000000".ToCharArray();
  339. polegry[5] = "0000000000".ToCharArray();
  340. polegry[6] = "0000000000".ToCharArray();
  341. polegry[7] = "0000000000".ToCharArray();
  342. polegry[8] = "0000000000".ToCharArray();
  343. polegry[9] = "0000000000".ToCharArray();
  344. wypisz(polegry);
  345. int[] tab = new int[2];
  346. tab = evaluateBoard(polegry);
  347. Console.WriteLine("Punkty bialych:" + tab[0]);
  348. Console.WriteLine("Punkty czarnych:" + tab[1]);
  349. Console.ReadKey();
  350. }
  351. }
  352. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement