Advertisement
LucasSousa

TENTATIVA SCRAMBLE 3X3 II

Nov 26th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. package rascunhos_etc;
  2.  
  3. import java.util.*;
  4.  
  5. public class NewClass {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Random r = new Random();
  10.  
  11. String[] globalMoves = {"F ", "B ", "U ", "D ", "R ", "L "};
  12.  
  13. //Arrays classificados
  14. String[] moves1 = {"B ", "F "};
  15. String[] moves2 = {"D ", "U "};
  16. String[] moves3 = {"L ", "R "};
  17.  
  18.  
  19. String m1 = globalMoves[r.nextInt(6)];
  20.  
  21. String m2 = "";
  22.  
  23. do {
  24. m2 = globalMoves[r.nextInt(6)];
  25. } while (m2 == m1);
  26.  
  27. int testeA = Arrays.binarySearch(moves1, m1);
  28. int testeB = Arrays.binarySearch(moves2, m1);
  29. int testeC = Arrays.binarySearch(moves3, m1);
  30.  
  31. int testeD = Arrays.binarySearch(moves1, m2);
  32. // int teste21 = Arrays.binarySearch(moves2, m2);
  33. // int teste31 = Arrays.binarySearch(moves3, m2);
  34.  
  35. String m3 = "";
  36.  
  37. do {
  38. if (testeD == testeA || testeD == testeB || testeD == testeC) {
  39.  
  40. m3 = moves2[r.nextInt(2)];//~~
  41.  
  42. } else {
  43.  
  44. m3 = globalMoves[r.nextInt(6)];
  45. }
  46.  
  47. } while (m3 == m2);
  48.  
  49. int testeE = Arrays.binarySearch(moves1, m2);
  50. int testeF = Arrays.binarySearch(moves2, m2);
  51. int testeG = Arrays.binarySearch(moves3, m2);
  52.  
  53. int testeH = Arrays.binarySearch(moves1, m3);
  54.  
  55. String m4 = "";
  56.  
  57. do {
  58. if (testeH == testeE || testeH == testeF || testeH == testeG) {
  59.  
  60. m4 = moves2[r.nextInt(2)];//~~
  61.  
  62. } else {
  63.  
  64. m4 = globalMoves[r.nextInt(6)];
  65. }
  66.  
  67. } while (m4 == m3);
  68.  
  69. int testeI = Arrays.binarySearch(moves1, m3);
  70. int testeJ = Arrays.binarySearch(moves2, m3);
  71. int testeK = Arrays.binarySearch(moves3, m3);
  72.  
  73. int testeL = Arrays.binarySearch(moves1, m4);
  74.  
  75. String m5 = "";
  76.  
  77. do {
  78. if (testeL == testeI || testeL == testeJ || testeL == testeK) {
  79.  
  80. m5 = moves2[r.nextInt(2)];//~~
  81.  
  82. } else {
  83.  
  84. m5 = globalMoves[r.nextInt(6)];
  85. }
  86.  
  87. } while (m5 == m4);
  88.  
  89.  
  90.  
  91. System.out.println(m1 + m2 + m3 + m4 + m5);
  92.  
  93. //se value (m2) for encontrado na busca, binarySearch retorna
  94. //o índice do elemento; caso contrário, binarySearch retorna
  95. //um valor negativo.
  96. //procurando o valor
  97. //enquanto m3 pertencer ao array de m1: sortear de novo, mas apenas se m3 e m1 pertencer ao array de m2;
  98. //enquanto m3 for do mesmo array de m2: sortear de novo;
  99. //se m2 não pertencer ao array de m1: sortear qualquer um de globalMoves;
  100. //se m2 pertencer ao array de m1: sortear um valor de qualquer array, exceto do array de m1;
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement