Advertisement
idekpas

Untitled

May 20th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 109.14 KB | None | 0 0
  1. using System.Linq;
  2. using Evertop.Soccer.Common;
  3. using System.Collections.Generic;
  4.  
  5. namespace SocLib_v1_1_2
  6. {
  7. class Zawodowiec : IPlayer
  8. {
  9. private Direction[] allDirections = new Direction[8];
  10. private FieldData Map;
  11. private int Side;
  12.  
  13. public string Name
  14. {
  15. get
  16. {
  17. return "Cancer";
  18. }
  19. }
  20.  
  21. private int ballSector(int x, int y, int length, int width)
  22. {
  23. if (y == 0) return 0; // górna krawędź
  24. if (y == 1 && x > 0 && x < length) return 1; // przy górnej krawędzi
  25. if (y == width) return 2; // dolna krawędź
  26. if (y == width - 1 && x > 0 && x < length) return 3; // przy dolnej krawędzi
  27. if (y == width / 2 && x == length / 2) return 4; // środek
  28. if(Side == 1)
  29. {
  30. if (x == 0 && y >= (width / 2) - 1 && y <= (width / 2) + 1) return 5; // bramka przeciwnika
  31. if (x == 0 && y < (width / 2) - 1) return 6; // nad bramką przeciwnika
  32. if (x == 0 && y > (width / 2) + 1) return 7; // pod bramką przeciwnika
  33. if (x == length && y == width / 2) return 8; // twoja bramka
  34. if (x == length && y == (width / 2) - 1) return 23; // górny słupek twojej bramki
  35. if (x == length && y == (width / 2) + 1) return 24; // dolny słupek twojej bramki
  36. if (x == length -1 && y == (width / 2) - 2) return 25; // górny słupek twojej bramki +1/1
  37. if (x == length -1 && y == (width / 2) + 2) return 26; // dolny słupek twojej bramki +1/1
  38. if (x == length && y < width / 2) return 9; // nad twoją bramką
  39. if (x == length && y > width / 2) return 10; // pod twoją bramką
  40. if (x == 1 && y == width / 2) return 11; // naprzeciwko bramki przeciwnika
  41. if (x == 1 && y == (width / 2) - 1) return 12; // naprzeciwko górnego słupka przeciwnika
  42. if (x == 1 && y == (width / 2) + 1) return 13; // naprzeciwko dolnego słupka przeciwnika
  43. if (x == length - 1 && y == width / 2) return 14; // naprzeciwko bramki twojej
  44. if (x == length - 1 && y == (width / 2) - 1) return 15; // naprzeciwko górnego słupka twojej
  45. if (x == length - 1 && y == (width / 2) + 1) return 16; // naprzeciwko dolnego słupka twojej
  46. if (x == 1 && y > (width / 2) + 1) return 17; // dolne bramkowe przeciwnika
  47. if (x == 1 && y < (width / 2) - 1) return 18; // górne bramkowe przeciwnika
  48. if (x == length - 1 && y > (width / 2) + 1) return 19; // dolne bramkowe twoje
  49. if (x == length - 1 && y < (width / 2) - 1) return 20; // górne bramkowe twoje
  50. if (y < width / 2) return 21; // połowa przeciwnika
  51. if (y >= width / 2) return 22; // twoja połowa
  52. }
  53. if (x == length && y >= (width / 2) - 1 && y <= (width / 2) + 1) return 5; // bramka przeciwnika
  54. if (x == length && y < (width / 2) - 1) return 6; // nad bramką przeciwnika
  55. if (x == length && y > (width / 2) + 1) return 7; // pod bramką przeciwnika
  56. if (x == 0 && y == width / 2) return 8; // twoja bramka
  57. if (x == 0 && y == (width / 2) - 1) return 23; // górny słupek twojej bramki
  58. if (x == 0 && y == (width / 2) + 1) return 24; // dolny słupek twojej bramki
  59. if (x == 1 && y == (width / 2) - 2) return 25; // górny słupek twojej bramki +1/1
  60. if (x == 1 && y == (width / 2) + 2) return 26; // dolny słupek twojej bramki +1/1
  61. if (x == 0 && y < width / 2) return 9; // nad twoją bramką
  62. if (x == 0 && y > width / 2) return 10; // pod twoją bramką
  63. if (x == length - 1 && y == width / 2) return 11; // naprzeciwko bramki przeciwnika
  64. if (x == length - 1 && y == (width / 2) - 1) return 12; // naprzeciwko górnego słupka przeciwnika
  65. if (x == length - 1 && y == (width / 2) + 1) return 13; // naprzeciwko dolnego słupka przeciwnika
  66. if (x == 1 && y == width / 2) return 14; // naprzeciwko bramki twojej
  67. if (x == 1 && y == (width / 2) - 1) return 15; // naprzeciwko górnego słupka twojej
  68. if (x == 1 && y == (width / 2) + 1) return 16; // naprzeciwko dolnego słupka twojej
  69. if (x == length - 1 && y > (width / 2) + 1) return 17; // dolne bramkowe przeciwnika
  70. if (x == length - 1 && y < (width / 2) - 1) return 18; // górne bramkowe przeciwnika
  71. if (x == 1 && y > (width / 2) + 1) return 19; // dolne bramkowe twoje
  72. if (x == 1 && y < (width / 2) - 1) return 20; // górne bramkowe twoje
  73. if (y > width / 2) return 21; // połowa przeciwnika
  74. if (y <= width / 2) return 22; // twoja połowa
  75. return -1;
  76. }
  77.  
  78. private Direction oppositeDirection(Direction dir)
  79. {
  80. if (dir == Direction.Up) return Direction.Down;
  81. if (dir == Direction.Down) return Direction.Up;
  82. if (dir == Direction.UpAndRight) return Direction.DownAndLeft;
  83. if (dir == Direction.DownAndLeft) return Direction.UpAndRight;
  84. if (dir == Direction.Left) return Direction.Right;
  85. if (dir == Direction.Right) return Direction.Left;
  86. if (dir == Direction.RightAndDown) return Direction.LeftAndUp;
  87. if (dir == Direction.LeftAndUp) return Direction.RightAndDown;
  88. return dir;
  89. }
  90.  
  91. private Direction[] ownPossibleDirections(Position pos, Move[] _historyMoves, Direction lastDirection)
  92. {
  93. int sectorN = ballSector(pos.X, pos.Y, Map.Length, Map.Width);
  94. List <Direction> list = new List<Direction>();
  95. List <Direction> list2 = new List<Direction>();
  96. list.Add(Direction.Up);
  97. list.Add(Direction.UpAndRight);
  98. list.Add(Direction.Right);
  99. list.Add(Direction.RightAndDown);
  100. list.Add(Direction.Down);
  101. list.Add(Direction.DownAndLeft);
  102. list.Add(Direction.Left);
  103. list.Add(Direction.LeftAndUp);
  104. list2.Add(Direction.Up);
  105. list2.Add(Direction.UpAndRight);
  106. list2.Add(Direction.Right);
  107. list2.Add(Direction.RightAndDown);
  108. list2.Add(Direction.Down);
  109. list2.Add(Direction.DownAndLeft);
  110. list2.Add(Direction.Left);
  111. list2.Add(Direction.LeftAndUp);
  112.  
  113. int indexer = 0;
  114. foreach (Direction dir in list2)
  115. {
  116. indexer = 0;
  117. foreach (Move ruch in _historyMoves)
  118. {
  119. if (ruch.Start.X == pos.X && ruch.Start.Y == pos.Y)
  120. {
  121. list.Remove(ruch.Direction);
  122. if (indexer-1>=0)
  123. list.Remove(oppositeDirection(_historyMoves[indexer-1].Direction));
  124. }
  125. indexer++;
  126. }
  127. }
  128.  
  129. if (lastDirection == Direction.Up) list.Remove(Direction.Down);
  130. if (lastDirection == Direction.Down) list.Remove(Direction.Up);
  131. if (lastDirection == Direction.UpAndRight) list.Remove(Direction.DownAndLeft);
  132. if (lastDirection == Direction.DownAndLeft) list.Remove(Direction.UpAndRight);
  133. if (lastDirection == Direction.Left) list.Remove(Direction.Right);
  134. if (lastDirection == Direction.Right) list.Remove(Direction.Left);
  135. if (lastDirection == Direction.RightAndDown) list.Remove(Direction.LeftAndUp);
  136. if (lastDirection == Direction.LeftAndUp) list.Remove(Direction.RightAndDown);
  137.  
  138. switch (sectorN)
  139. {
  140. case 0:
  141. list.Remove(Direction.Up);
  142. list.Remove(Direction.UpAndRight);
  143. list.Remove(Direction.LeftAndUp);
  144. list.Remove(Direction.Left);
  145. list.Remove(Direction.Right);
  146. break;
  147. case 2:
  148. list.Remove(Direction.Down);
  149. list.Remove(Direction.DownAndLeft);
  150. list.Remove(Direction.RightAndDown);
  151. list.Remove(Direction.Left);
  152. list.Remove(Direction.Right);
  153. break;
  154. case 6:
  155. case 7:
  156. if (Side == 1)
  157. {
  158. list.Remove(Direction.Up);
  159. list.Remove(Direction.Down);
  160. list.Remove(Direction.LeftAndUp);
  161. list.Remove(Direction.Left);
  162. list.Remove(Direction.DownAndLeft);
  163. }
  164. else
  165. {
  166. list.Remove(Direction.Up);
  167. list.Remove(Direction.Down);
  168. list.Remove(Direction.Right);
  169. list.Remove(Direction.RightAndDown);
  170. list.Remove(Direction.UpAndRight);
  171. }
  172. break;
  173. }
  174. return list.ToArray();
  175. }
  176.  
  177. private bool isWall(Position pos, Move[] _historyMoves)
  178. {
  179. int indexer = 0;
  180.  
  181. if (pos.X == 0 || pos.X == Map.Length || pos.Y == 0 || pos.Y == Map.Width)
  182. if(pos.Y != Map.Width/2) return true;
  183.  
  184. foreach (Move ruch in _historyMoves)
  185. {
  186. if (ruch.Start.X == pos.X && ruch.Start.Y == pos.Y) indexer++;
  187. }
  188. if (indexer > 0 && indexer < 4) return true;
  189. return false;
  190. }
  191.  
  192. private bool isPossible(Position _pos, Move[] _historyMoves, Direction[] possibleMoves, Direction direction)
  193. {
  194. Position pos = _pos;
  195. List<Move> ownHistoryMoves = new List<Move>();
  196. foreach (Move ruch in _historyMoves)
  197. {
  198. ownHistoryMoves.Add(ruch);
  199. }
  200.  
  201. if (direction == Direction.Up) pos = new Position(_pos.X, _pos.Y - 1);
  202. if (direction == Direction.UpAndRight) pos = new Position(_pos.X + 1, _pos.Y - 1);
  203. if (direction == Direction.Right) pos = new Position(_pos.X + 1, _pos.Y);
  204. if (direction == Direction.RightAndDown) pos = new Position(_pos.X + 1, _pos.Y + 1);
  205. if (direction == Direction.Down) pos = new Position(_pos.X, _pos.Y + 1);
  206. if (direction == Direction.DownAndLeft) pos = new Position(_pos.X - 1, _pos.Y + 1);
  207. if (direction == Direction.Left) pos = new Position(_pos.X - 1, _pos.Y);
  208. if (direction == Direction.LeftAndUp) pos = new Position(_pos.X - 1, _pos.Y - 1);
  209. int sectorN = ballSector(pos.X, pos.Y, Map.Length, Map.Width);
  210.  
  211. if ((pos.X == 0 &&pos.Y == 0) || (pos.X == 0 && pos.Y == Map.Width) || (pos.X == Map.Length && pos.Y == 0) || (pos.X == Map.Length && pos.Y == Map.Width))
  212. return false;
  213.  
  214. if (sectorN == 0 || sectorN == 2 || sectorN == 6 || sectorN == 7 || sectorN == 8 || sectorN == 9 || sectorN == 10 || sectorN == 23 || sectorN == 24)
  215. {
  216. foreach (Move ruch in _historyMoves)
  217. {
  218. if (ruch.Start.X == pos.X && ruch.Start.Y == pos.Y)
  219. return false;
  220. }
  221. }
  222.  
  223. int indexer = 0;
  224. if (sectorN == 4)
  225. {
  226. foreach (Move ruch in _historyMoves)
  227. {
  228. if (ruch.Start.X == pos.X && ruch.Start.Y == pos.Y) indexer++;
  229. }
  230. if (indexer == 3)
  231. return false;
  232. }
  233.  
  234. foreach (Move ruch in _historyMoves)
  235. {
  236. if (ruch.Start.X == _pos.X && ruch.Start.Y == _pos.Y && ruch.Direction == direction) return false;
  237. }
  238.  
  239. indexer = 0;
  240. foreach (Direction dir in possibleMoves)
  241. if (dir == direction) indexer++;
  242. if (indexer == 0)
  243. return false;
  244.  
  245. if(isWall(pos, _historyMoves) == true)
  246. {
  247. indexer = 0;
  248. ownHistoryMoves.Add(new Move(false, _pos, direction));
  249. foreach(Direction dir in ownPossibleDirections(pos, ownHistoryMoves.ToArray(), direction))
  250. if (isPossible(pos, ownHistoryMoves.ToArray(), ownPossibleDirections(pos, ownHistoryMoves.ToArray(), direction), dir))
  251. {
  252. indexer = 1;
  253. break;
  254. }
  255. ownHistoryMoves.Remove(ownHistoryMoves.Last());
  256. }
  257. if (indexer == 1)
  258. return true;
  259. return false;
  260. }
  261.  
  262. private Direction findBest (Move[] historyMoves, Position ballPosition, Direction[] possibleMoves)
  263. {
  264. Side = (int)Map.PlayerSide;
  265. int sector = ballSector(ballPosition.X, ballPosition.Y, Map.Length, Map.Width);
  266.  
  267. switch (sector)
  268. {
  269. case 0:
  270. if (Side == 1)
  271. {
  272. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  273. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  274. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  275. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  276. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  277. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  278. return possibleMoves.First();
  279. }
  280. else
  281. {
  282. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  283. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  284. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  285. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  286. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  287. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  288. return possibleMoves.Last();
  289. }
  290. case 1:
  291. if (Side == 1)
  292. {
  293. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  294. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  295. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  296. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  297. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  298. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  299. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  300. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  301. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  302. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  303. return possibleMoves.First();
  304. }
  305. else
  306. {
  307. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  308. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  309. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  310. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  311. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  312. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  313. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  314. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  315. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  316. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  317. return possibleMoves.Last();
  318. }
  319. case 2:
  320. if (Side == 1)
  321. {
  322. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  323. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  324. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  325. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  326. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  327. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  328. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  329. return possibleMoves.First();
  330. }
  331. else
  332. {
  333. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  334. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  335. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  336. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  337. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  338. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  339. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  340. return possibleMoves.First();
  341. }
  342. case 3:
  343. if (Side == 1)
  344. {
  345. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  346. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  347. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  348. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  349. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  350. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  351. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  352. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  353. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  354. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  355. return possibleMoves.Last();
  356. }
  357. else
  358. {
  359. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  360. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  361. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  362. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  363. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  364. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  365. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  366. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  367. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  368. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  369. return possibleMoves.First();
  370. }
  371. case 4:
  372. if (Side == 1)
  373. {
  374. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  375. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  376. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  377. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  378. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  379. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  380. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  381. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  382. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  383. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  384. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  385. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  386. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  387. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  388. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  389. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  390. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  391. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  392. return possibleMoves.Last();
  393. }
  394. else
  395. {
  396. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  397. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  398. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  399. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  400. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  401. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  402. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  403. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  404. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  405. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  406. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  407. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  408. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  409. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  410. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  411. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  412. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  413. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  414. return possibleMoves.First();
  415. }
  416. case 5:
  417. if (Side == 1) return possibleMoves.Last();
  418. else
  419. {
  420. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  421. return possibleMoves.First();
  422. }
  423. case 6:
  424. if (Side == 1)
  425. {
  426. if(isWall(new Position(ballPosition.X+1, ballPosition.Y+1), historyMoves))
  427. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  428. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  429. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  430. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  431. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  432. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  433. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  434. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  435. return possibleMoves.Last();
  436. }
  437. else
  438. {
  439. if (isWall(new Position(ballPosition.X -1 , ballPosition.Y + 1), historyMoves))
  440. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  441. if (isWall(new Position(ballPosition.X -1 , ballPosition.Y), historyMoves))
  442. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  443. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  444. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  445. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  446. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  447. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  448. return possibleMoves.First();
  449. }
  450. case 7:
  451. if (Side == 1)
  452. {
  453. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  454. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  455. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  456. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  457. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  458. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  459. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  460. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  461. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  462. return possibleMoves.First();
  463. }
  464. else
  465. {
  466. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  467. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  468. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  469. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  470. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  471. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  472. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  473. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  474. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  475. return possibleMoves.Last();
  476. }
  477. case 8:
  478. if (Side == 1)
  479. {
  480. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  481. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  482. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  483. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  484. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  485. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  486. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  487. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  488. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  489. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  490. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  491. return possibleMoves.Last();
  492. }
  493. else
  494. {
  495. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  496. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  497. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  498. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  499. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  500. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  501. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  502. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  503. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  504. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  505. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  506. return possibleMoves.First();
  507. }
  508. case 9:
  509. if (Side == 1)
  510. {
  511. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  512. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  513. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  514. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  515. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  516. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  517. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  518. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  519. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  520. return possibleMoves.Last();
  521. }
  522. else
  523. {
  524. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  525. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  526. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  527. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  528. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  529. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  530. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  531. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  532. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  533. return possibleMoves.First();
  534. }
  535. case 10:
  536. if (Side == 1)
  537. {
  538. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  539. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  540. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  541. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  542. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  543. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  544. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  545. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  546. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  547. return possibleMoves.First();
  548. }
  549. else
  550. {
  551. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  552. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  553. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  554. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  555. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  556. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  557. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  558. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  559. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  560. return possibleMoves.First();
  561. }
  562. case 11:
  563. if (Side == 1)
  564. {
  565. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  566. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  567. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  568. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  569. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  570. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  571. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  572. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  573. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  574. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  575. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  576. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  577. return possibleMoves.Last();
  578. }
  579. else
  580. {
  581. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  582. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  583. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  584. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  585. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  586. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  587. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  588. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  589. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  590. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  591. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  592. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  593. return possibleMoves.Last();
  594. }
  595. case 12:
  596. if (Side == 1)
  597. {
  598. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  599. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  600. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  601. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  602. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  603. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  604. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  605. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  606. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  607. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  608. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  609. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  610. return possibleMoves.First();
  611. }
  612. else
  613. {
  614. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  615. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  616. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  617. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  618. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  619. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  620. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  621. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  622. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  623. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  624. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  625. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  626. return possibleMoves.Last();
  627. }
  628. case 13:
  629. if (Side == 1)
  630. {
  631. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  632. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  633. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  634. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  635. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  636. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  637. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  638. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  639. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  640. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  641. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  642. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  643. return possibleMoves.First();
  644. }
  645. else
  646. {
  647. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  648. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  649. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  650. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  651. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  652. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  653. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  654. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  655. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  656. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  657. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  658. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  659. return possibleMoves.Last();
  660. }
  661. case 14:
  662. if (Side == 1)
  663. {
  664. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  665. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  666. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  667. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  668. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  669. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  670. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  671. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  672. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  673. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  674. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  675. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  676. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  677. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  678. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  679. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  680. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  681. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  682. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  683. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  684. return possibleMoves.Last();
  685. }
  686. else
  687. {
  688. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  689. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  690. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  691. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  692. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  693. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  694. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  695. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  696. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  697. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  698. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  699. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  700. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  701. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  702. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  703. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  704. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  705. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  706. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  707. return possibleMoves.First();
  708. }
  709. case 15:
  710. if (Side == 1)
  711. {
  712. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  713. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  714. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  715. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  716. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  717. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  718. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  719. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  720. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  721. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  722. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  723. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  724. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  725. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  726. return possibleMoves.First();
  727. }
  728. else
  729. {
  730. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  731. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  732. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  733. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  734. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  735. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  736. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  737. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  738. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  739. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  740. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  741. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  742. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  743. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  744. return possibleMoves.Last();
  745. }
  746. case 16:
  747. if (Side == 1)
  748. {
  749. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  750. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  751. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  752. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  753. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  754. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  755. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  756. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  757. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  758. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  759. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  760. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  761. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  762. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  763. return possibleMoves.First();
  764. }
  765. else
  766. {
  767. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  768. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  769. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  770. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  771. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  772. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  773. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  774. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  775. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  776. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  777. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  778. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  779. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  780. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  781. return possibleMoves.Last();
  782. }
  783. case 17:
  784. if (Side == 1)
  785. {
  786. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  787. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  788. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  789. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  790. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  791. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  792. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  793. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  794. return possibleMoves.First();
  795. }
  796. else
  797. {
  798. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  799. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  800. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  801. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  802. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  803. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  804. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  805. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  806. return possibleMoves.Last();
  807. }
  808. case 18:
  809. if (Side == 1)
  810. {
  811. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  812. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  813. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  814. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.LeftAndUp;
  815. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  816. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  817. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  818. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  819. return possibleMoves.First();
  820. }
  821. else
  822. {
  823. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  824. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  825. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  826. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  827. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  828. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  829. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  830. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  831. return possibleMoves.Last();
  832. }
  833. case 19:
  834. if (Side == 1)
  835. {
  836. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  837. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  838. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  839. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  840. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  841. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  842. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  843. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  844. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  845. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  846. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  847. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  848. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  849. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  850. return possibleMoves.Last();
  851. }
  852. else
  853. {
  854. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  855. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  856. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  857. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  858. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  859. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  860. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  861. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  862. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  863. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  864. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  865. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  866. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  867. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  868. return possibleMoves.First();
  869. }
  870. case 20:
  871. if (Side == 1)
  872. {
  873. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  874. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  875. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  876. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  877. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  878. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  879. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  880. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  881. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  882. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  883. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  884. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  885. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  886. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  887. return possibleMoves.Last();
  888. }
  889. else
  890. {
  891. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  892. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  893. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  894. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  895. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  896. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  897. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  898. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  899. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  900. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  901. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  902. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  903. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  904. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  905. return possibleMoves.First();
  906. }
  907. case 21:
  908. if (Side == 1)
  909. {
  910. if (ballPosition.Y > Map.Width / 2)
  911. {
  912. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  913. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  914. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  915. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  916. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  917. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  918. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  919. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  920. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  921. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  922. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  923. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  924. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  925. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  926. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  927. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  928. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  929. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  930. return possibleMoves.Last();
  931. }
  932. else
  933. {
  934. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  935. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  936. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  937. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  938. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  939. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  940. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  941. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  942. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  943. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  944. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  945. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  946. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  947. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  948. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Up;
  949. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  950. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  951. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  952. return possibleMoves.First();
  953. }
  954. }
  955. else
  956. {
  957. if (ballPosition.Y > Map.Width / 2)
  958. {
  959. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  960. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  961. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  962. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  963. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  964. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  965. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  966. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  967. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  968. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  969. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  970. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  971. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  972. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  973. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  974. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  975. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  976. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  977. return possibleMoves.Last();
  978. }
  979. else
  980. {
  981. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  982. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  983. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  984. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  985. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  986. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  987. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  988. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  989. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  990. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  991. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  992. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  993. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  994. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  995. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  996. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  997. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  998. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  999. return possibleMoves.Last();
  1000. }
  1001. }
  1002. case 22:
  1003. if (Side == 1)
  1004. {
  1005. if (ballPosition.Y > Map.Width / 2)
  1006. {
  1007. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  1008. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1009. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  1010. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1011. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  1012. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1013. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  1014. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1015. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  1016. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1017. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1018. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1019. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1020. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1021. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1022. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1023. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1024. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1025. return possibleMoves.Last();
  1026. }
  1027. else
  1028. {
  1029. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  1030. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1031. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  1032. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1033. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  1034. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1035. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  1036. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1037. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  1038. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1039. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1040. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1041. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1042. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1043. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Up;
  1044. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1045. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1046. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1047. return possibleMoves.First();
  1048. }
  1049. }
  1050. else
  1051. {
  1052. if (ballPosition.Y > Map.Width / 2)
  1053. {
  1054. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  1055. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1056. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  1057. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1058. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  1059. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1060. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  1061. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1062. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  1063. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1064. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1065. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1066. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1067. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1068. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1069. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1070. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1071. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1072. return possibleMoves.Last();
  1073. }
  1074. else
  1075. {
  1076. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  1077. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1078. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  1079. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1080. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  1081. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1082. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  1083. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1084. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  1085. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1086. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1087. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1088. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1089. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1090. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1091. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1092. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1093. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1094. return possibleMoves.Last();
  1095. }
  1096. }
  1097. case 23:
  1098. if (Side == 1)
  1099. {
  1100. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1101. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1102. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  1103. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1104. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  1105. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1106. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1107. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1108. return possibleMoves.Last();
  1109. }
  1110. else
  1111. {
  1112. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1113. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1114. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  1115. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1116. if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
  1117. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1118. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1119. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1120. return possibleMoves.First();
  1121. }
  1122. case 24:
  1123. if (Side == 1)
  1124. {
  1125. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1126. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1127. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  1128. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1129. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  1130. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1131. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1132. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1133. return possibleMoves.Last();
  1134. }
  1135. else
  1136. {
  1137. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1138. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1139. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  1140. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1141. if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
  1142. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1143. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1144. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1145. return possibleMoves.First();
  1146. }
  1147. case 25:
  1148. if (Side == 1)
  1149. {
  1150. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  1151. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1152. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  1153. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1154. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  1155. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1156. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1157. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1158. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1159. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1160. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1161. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1162. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1163. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1164. return possibleMoves.Last();
  1165. }
  1166. else
  1167. {
  1168. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  1169. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1170. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  1171. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1172. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  1173. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1174. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1175. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1176. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1177. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1178. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1179. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1180. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1181. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1182. return possibleMoves.Last();
  1183. }
  1184. case 26:
  1185. if (Side == 1)
  1186. {
  1187. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
  1188. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1189. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
  1190. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1191. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
  1192. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1193. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1194. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1195. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1196. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1197. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1198. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Up;
  1199. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1200. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Down;
  1201. return possibleMoves.Last();
  1202. }
  1203. else
  1204. {
  1205. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
  1206. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1207. if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
  1208. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1209. if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
  1210. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1211. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
  1212. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
  1213. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
  1214. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
  1215. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
  1216. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
  1217. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
  1218. if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
  1219. return possibleMoves.Last();
  1220. }
  1221. case -1:
  1222. if (Side == 1) return possibleMoves.Last();
  1223. return possibleMoves.First();
  1224. default:
  1225. if (Side == 1) return possibleMoves.Last();
  1226. return possibleMoves.First();
  1227. }
  1228. }
  1229.  
  1230. public Direction GetNextMove(Move[] historyMoves, Position ballPosition, Direction[] possibleMoves)
  1231. {
  1232. Side = (int)Map.PlayerSide;
  1233. return findBest(historyMoves, ballPosition, possibleMoves);
  1234. }
  1235.  
  1236. public void StartMatch(FieldData field)
  1237. {
  1238. Map = field;
  1239. allDirections[0] = Direction.Up;
  1240. allDirections[1] = Direction.UpAndRight;
  1241. allDirections[2] = Direction.Right;
  1242. allDirections[3] = Direction.RightAndDown;
  1243. allDirections[4] = Direction.Down;
  1244. allDirections[5] = Direction.DownAndLeft;
  1245. allDirections[6] = Direction.Left;
  1246. allDirections[7] = Direction.LeftAndUp;
  1247. }
  1248. }
  1249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement