Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int ThirdRule(int[][]matrix) {
- int penalty=0;
- int[]test1= {W,W,W,W,B,W,B,B,B,W,B};
- int[] test2= {B,W,B,B,B,W,B,W,W,W,W};
- int ligne = 0;
- int comboTest1 = 0;
- int comboTest2 = 0;
- int sequence1 = 0;
- int sequence2 = 0;
- boolean superpos = false;
- //ligne
- for(int i=0;i<matrix.length;++i) {
- while ((ligne < matrix.length -1) && (sequence1<2)) {
- if(test1[comboTest1] == matrix[ligne][i]) {
- if(comboTest1 == test1.length-1) {
- penalty += 40;
- ++sequence1;
- comboTest1 = 0;
- }
- ++comboTest1;
- }else {
- comboTest1=0;
- }
- if(test2[comboTest2] == matrix[ligne][i]) {
- if(comboTest2 == test2.length-1) {
- penalty += 40;
- superpos= true;
- ++sequence1;
- comboTest2 = 0;
- }
- if ((superpos == true) && (ligne>=19)) {
- for (int j=0; j<(8) && (superpos == true); ++j) {
- if(test1[test1.length-4-j]!= matrix[ligne-j-11][i]) {
- superpos = false;
- }
- }
- if (superpos == true) {
- penalty -= 40;
- superpos = false;
- }
- }
- ++comboTest2;
- }else {
- comboTest2=0;
- }
- ++ligne;
- }
- comboTest2 = 0;
- comboTest1 = 0;
- ligne = 0;
- // here "ligne" represents column
- while ((ligne < matrix.length -1) && (sequence2<2)) {
- if(test1[comboTest1] == matrix[i][ligne]) {
- if(comboTest1 == test1.length-2 ) {
- penalty += 40;
- ++sequence2;
- comboTest1 = 0;
- }
- ++comboTest1;
- }else {
- comboTest1=0;
- }
- if(test2[comboTest2] == matrix[i][ligne]) {
- if(comboTest2 == test2.length-1 ) {
- penalty += 40;
- ++sequence2;
- comboTest2 = 0;
- superpos = true;
- }
- if ((superpos == true) && (ligne>=19)) {
- for (int j=0; j<(8) && (superpos == true); ++j) {
- if(test1[test1.length-4-j]!= matrix[i][ligne-j-11]) {
- superpos = false;
- }
- }
- if (superpos == true) {
- penalty -= 40;
- superpos = false;
- }
- }
- ++comboTest2;
- }else {
- comboTest2=0;
- }
- ++ligne;
- }
- ligne = 0;
- comboTest1 = 0;
- comboTest2 = 0;
- }
- //colonne
- return penalty;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement