猜数2

来源:互联网 发布:上海大学网络选课系统 编辑:程序博客网 时间:2024/06/11 21:18
 

private void filterList(List<int[]> ls, List<int[]> temp, int[] guess,
   int A, int B) {
  int num = A + B;
  System.out.println("num: "+num);
  computer.setA(A);
  computer.setB(B);
  computer.setGuess(guess);
  computers.add(computer);
  tag: for (int[] tt : ls) {
   int m = 0;
   int n = 0;
   for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
     if (tt[i] == guess[j]) {
      if (i == j) {
       m++;
      } else if (i != j) {
       n++;
      }
     }
    }
   }
   if (num == 0) {
    if (m==0&&n==0) {
     temp.add(tt);         temp.add(tt);
    }
    continue tag;
        
   } else if (num < 4) {

    if ((m + n) > num)
     continue tag;
    else if (m > A || n > B)
     continue tag;
    else
     temp.add(tt);
   } else if (num == 4 && (m + n) == num) {
    if (m > 4 - B)
     continue tag;
    else if (n > (4 - A))
     continue tag;
    else
     temp.add(tt);
   }
  }

 }