Advertisement
sam1509

Untitled

Nov 9th, 2019
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. public static int ThirdRule(int[][]matrix) {
  2. int penalty=0;
  3.  
  4. int[]test1= {W,W,W,W,B,W,B,B,B,W,B};
  5.  
  6. int[] test2= {B,W,B,B,B,W,B,W,W,W,W};
  7.  
  8. int ligne = 0;
  9. int comboTest1 = 0;
  10. int comboTest2 = 0;
  11. int sequence1 = 0;
  12. int sequence2 = 0;
  13. boolean superpos = false;
  14. //ligne
  15. for(int i=0;i<matrix.length;++i) {
  16.  
  17. while ((ligne < matrix.length -1) && (sequence1<2)) {
  18.  
  19. if(test1[comboTest1] == matrix[ligne][i]) {
  20.  
  21. if(comboTest1 == test1.length-1) {
  22. penalty += 40;
  23. ++sequence1;
  24. comboTest1 = 0;
  25. }
  26. ++comboTest1;
  27. }else {
  28. comboTest1=0;
  29. }
  30. if(test2[comboTest2] == matrix[ligne][i]) {
  31.  
  32. if(comboTest2 == test2.length-1) {
  33.  
  34. penalty += 40;
  35. superpos= true;
  36. ++sequence1;
  37. comboTest2 = 0;
  38. }
  39.  
  40. if ((superpos == true) && (ligne>=19)) {
  41. for (int j=0; j<(8) && (superpos == true); ++j) {
  42.  
  43. if(test1[test1.length-4-j]!= matrix[ligne-j-11][i]) {
  44. superpos = false;
  45. }
  46.  
  47.  
  48. }
  49. if (superpos == true) {
  50. penalty -= 40;
  51. superpos = false;
  52. }
  53. }
  54. ++comboTest2;
  55. }else {
  56. comboTest2=0;
  57. }
  58.  
  59.  
  60. ++ligne;
  61. }
  62.  
  63. comboTest2 = 0;
  64. comboTest1 = 0;
  65. ligne = 0;
  66.  
  67. // here "ligne" represents column
  68. while ((ligne < matrix.length -1) && (sequence2<2)) {
  69.  
  70. if(test1[comboTest1] == matrix[i][ligne]) {
  71.  
  72.  
  73. if(comboTest1 == test1.length-2 ) {
  74.  
  75. penalty += 40;
  76.  
  77. ++sequence2;
  78.  
  79.  
  80.  
  81. comboTest1 = 0;
  82. }
  83. ++comboTest1;
  84. }else {
  85. comboTest1=0;
  86. }
  87. if(test2[comboTest2] == matrix[i][ligne]) {
  88.  
  89. if(comboTest2 == test2.length-1 ) {
  90. penalty += 40;
  91. ++sequence2;
  92. comboTest2 = 0;
  93. superpos = true;
  94. }
  95.  
  96. if ((superpos == true) && (ligne>=19)) {
  97. for (int j=0; j<(8) && (superpos == true); ++j) {
  98. if(test1[test1.length-4-j]!= matrix[i][ligne-j-11]) {
  99. superpos = false;
  100. }
  101.  
  102.  
  103. }
  104. if (superpos == true) {
  105. penalty -= 40;
  106. superpos = false;
  107. }
  108. }
  109. ++comboTest2;
  110. }else {
  111. comboTest2=0;
  112. }
  113.  
  114.  
  115. ++ligne;
  116. }
  117.  
  118. ligne = 0;
  119. comboTest1 = 0;
  120. comboTest2 = 0;
  121.  
  122. }
  123.  
  124.  
  125. //colonne
  126.  
  127.  
  128.  
  129.  
  130. return penalty;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement