Guest User

Untitled

a guest
Nov 14th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. package players;
  2. public class SuJugador implements Player
  3. {
  4. public int[] move(int[][] history, int player)
  5. {
  6. int [] Move= new int [2];
  7. int x=history[history.length-1][0];
  8. int y=history[history.length-1][1];
  9. /*.
  10. * |---|---|---|
  11. * | 1 | 2 | 3 |
  12. * |---|---|---|
  13. * | |
  14. * | 4 |
  15. * | |
  16. * |___________|
  17. * | 5 | 6 | 7 |
  18. * |---|---|---|
  19. */
  20. if (player == 0)
  21. {
  22. // CUANDO LLEGUE A LA CACHA DE ARRIBA
  23. if((x==4)&&(y==2))
  24. {
  25. Move=casos(1, history);
  26. if((validMove(Move,history)==true)&&
  27. (limit(Move[0],Move[1])==true))
  28. {
  29. return Move;
  30. }
  31. }
  32. if((x==5)&&(y==2))
  33. {
  34. Move=casos(2, history);
  35. if((validMove(Move,history)==true)&&
  36. (limit(Move[0],Move[1])==true))
  37. {
  38. return Move;
  39. }
  40. }
  41. if((x==6)&&(y==2))
  42. {
  43. Move=casos(3, history);
  44. if((validMove(Move,history)==true)&&
  45. (limit(Move[0],Move[1])==true))
  46. {
  47. return Move;
  48. }
  49. }
  50. //Medio Total
  51. if((x==5)&&(y==7))
  52. {
  53. Move=casos(1, history);
  54. if((validMove(Move,history)==true)&&
  55. (limit(Move[0],Move[1])==true))
  56. {
  57. return Move;
  58. }
  59. }
  60. }
  61. return null;
  62. }
  63. }
  64. public static int[] casos(int $id,int[][]history)
  65. {
  66. {
  67. int [] Move= new int [2];
  68. int x=history[history.length-1][0];
  69. int y=history[history.length-1][1];
  70. switch ($id)
  71. {
  72. case 1: x=history[history.length-1][0];
  73. y=history[history.length-1][1];
  74. Move[0]=x;
  75. Move[1]=y-1;
  76. break;
  77.  
  78. case 2: x=history[history.length-1][0];
  79. y=history[history.length-1][1];
  80. Move[0]=x+1;
  81. Move[1]=y-1;
  82. break;
  83.  
  84. case 3: x=history[history.length-1][0];
  85. y=history[history.length-1][1];
  86. Move[0]=x-1;
  87. Move[1]=y-1;
  88. break;
  89.  
  90. case 4: x=history[history.length-1][0];
  91. y=history[history.length-1][1];
  92. Move[0]=x;
  93. Move[1]=y+1;
  94. break;
  95.  
  96.  
  97. case 5: x=history[history.length-1][0];
  98. y=history[history.length-1][1];
  99. Move[0]=x+1;
  100. Move[1]=y;
  101. break;
  102.  
  103. case 6: x=history[history.length-1][0];
  104. y=history[history.length-1][1];
  105. Move[0]=x-1;
  106. Move[1]=y;
  107. break;
  108.  
  109. case 7: x=history[history.length-1][0];
  110. y=history[history.length-1][1];
  111. Move[0]=x+1;
  112. Move[1]=y+1;
  113. break;
  114.  
  115. case 8: x=history[history.length-1][0];
  116. y=history[history.length-1][1];
  117. Move[0]=x-1;
  118. Move[1]=y+1;
  119. break;
  120.  
  121. }
  122. }
  123. return false;
  124. }
  125. public static boolean limit (int x, int y)
  126. {
  127. if ((x>=1)&&(x<=9)&&(y>=2)&&(y<=12))
  128. {
  129. return true;
  130. }
  131. if (((y==1)||(y==13))&&(x==4)||(x==5)||(x==6))
  132. {
  133. return true;
  134. }
  135. return false;
  136. }
  137. public static boolean validMove(int []FutMov,int[][]history)
  138. {
  139. if (history.length>1)
  140. {
  141. boolean permitex=false;
  142. boolean permitey=false;
  143. int Posx=history[history.length-1][0];
  144. int Posy=history[history.length-1][1];
  145.  
  146. for (int i=0;i<history.length-1;i++)
  147. {
  148.  
  149. if (history[i][0]== Posx)
  150. {
  151. if (history[i+1][0]== FutMov[0])
  152. {
  153. permitex =false;
  154. }
  155. else
  156. {
  157. permitex= true;
  158. }
  159. }
  160. if (history[i][1]==Posy)
  161. {
  162. if (history[i+1][1]== FutMov[1])
  163. {
  164. permitey=false;
  165. }
  166. else
  167. {
  168. permitey= true;
  169. }
  170. }
  171. }
  172. return (permitey||permitex);
  173. }
  174. return false;
  175. }
  176. }
Add Comment
Please, Sign In to add comment