📄 superuncle.java
字号:
public class SuperUncle {
private final int module1[] = {1,1,1,1,1};
private final int module2[] = {0,1,1,1,1,0};
private final int module3[] = {0,1,1,1,0,0};
private final int module4[] = {0,0,1,1,1,0};
private final int module5[] = {0,1,1,0,1,0};
private final int module6[] = {0,1,0,1,1,0};
private final int module7[] = {1,1,1,1,0};
private final int module8[] = {0,1,1,1,1};
private final int module9[] = {1,1,0,1,1};
private final int module10[] = {1,0,1,1,1};
private final int module11[] = {1,1,1,0,1};
private final int module12[] = {0,0,1,1,0,0};
private final int module13[] = {0,0,1,0,1,0};
private final int module14[] = {0,1,0,1,0,0};
private final int module15[] = {0,0,0,1,0,0};
private final int module16[] = {0,0,1,0,0,0};
private final int WEIGHT1 = 50000;
private final int WEIGHT2 = 4320;
private final int WEIGHT3 = 720;
private final int WEIGHT4 = 120;
private final int WEIGHT5 = 20;
private final int RANGE = 2;
public int[] recursiveSeek(int [][]table, int depth, int color, int mode, int []value, int row, int column, int upex, int mostleft) {
if(mode==0) value[0] = -50000;
else value[0]=50000;
int res[] = new int[2];
res[0] = -1;
int count=0;
int myex;
if(mode==0) myex=-60000;
else myex = 60000;
for(int i=(row-RANGE > 0 ? row-RANGE : 0);i<=(row+RANGE < 14 ? row+RANGE : 14);i++){
for(int j=(column-RANGE > 0 ? column-RANGE : 0);j<=(column+RANGE < 14 ? column+RANGE : 14);j++){
if(table[i][j]==0){
table[i][j] = color + 1;
if(depth==0){ //end of recursive
int ora = overall(table, color);
if(mode==0){
if(ora>value[0]){
value[0]=ora;
res[0] = i;
res[1] = j;
}
if(value[0]>upex && mostleft>0) {value[0]=upex; table[i][j] = 0; return res;}
}
else{
if(ora<value[0]){
value[0]=ora;
res[0] = i;
res[1] = j;
}
if(value[0]<upex && mostleft>0) {value[0]=upex; table[i][j] = 0; return res;}
}
}
else{ // not end
recursiveSeek(table, depth-1, 1-color, 1-mode, value, i, j, myex, count);
if(mode==0){
if(myex<value[0]){
myex = value[0];
res[0] = i;
res[1] = j;
}
if(myex>upex && mostleft>0) {value[0]=upex; table[i][j] = 0; return res;}
}
else{
if(myex>value[0]){
myex = value[0];
res[0] = i;
res[1] = j;
}
if(myex<upex && mostleft>0) {value[0]=upex; table[i][j] = 0; return res;}
}
}
table[i][j] = 0;
count++;
}
}
}
return res;
}
private int overall(int [][]a, int color){
int result = heng(a, color) + shu(a, color) + pie(a, color) + na(a, color);
return result;
}
private boolean compare(int []left, int []right, int color, int start) {
boolean flag = true;
for(int i=0;i<right.length;i++) {
if(left[start+i]==2) left[start+i] -= color;
else if(left[start+i]==1) left[start+i] += color;
if(left[start+i]!=right[i]){
flag = false;
if(left[start+i]==1) left[start+i] += color;
else if(left[start+i]==2) left[start+i] -= color;
break;
}
if(left[start+i]==1) left[start+i] += color;
else if(left[start+i]==2) left[start+i] -= color;
}
return flag;
}
private int calculate_line(int []line, int mycolor){
int result = 0;
for(int k=0;k<line.length-4;k++){
if(compare(line, module1, mycolor, k)){
return WEIGHT1;
}
}
int j=0;
while(j<line.length-4){
if(compare(line, module1, mycolor, j)){
result += WEIGHT1;
j+=module1.length;
continue;
}
if(j<line.length-5){
if(compare(line, module2, mycolor, j)){
result += WEIGHT2;
j+=module2.length;
continue;
}
if(compare(line, module3, mycolor, j) || compare(line, module4, mycolor, j)
|| compare(line, module5, mycolor, j) || compare(line, module6, mycolor, j)){
result += WEIGHT3;
j+=module3.length;
continue;
}
}
if(compare(line, module7, mycolor, j) || compare(line, module8, mycolor, j)
|| compare(line, module9, mycolor, j) || compare(line, module10, mycolor, j)
|| compare(line, module11, mycolor, j)){
result += WEIGHT3;
j+=module7.length;
continue;
}
if(j<line.length-5){
if(compare(line, module12, mycolor, j) || compare(line, module13, mycolor, j)
|| compare(line, module14, mycolor, j)){
result += WEIGHT4;
j+=module12.length;
continue;
}
if(compare(line, module15, mycolor, j) || compare(line, module16, mycolor, j)){
result += WEIGHT5;
j+=module15.length;
continue;
}
}
j++;
}
j=0;
while(j<line.length-4){
if(compare(line, module1, (mycolor+1)%2, j)){
result -= WEIGHT1;
j+=module1.length;
continue;
}
if(j<line.length-5){
if(compare(line, module2, (mycolor+1)%2, j)){
result -= WEIGHT2;
j+=module2.length;
continue;
}
if(compare(line, module3, (mycolor+1)%2, j) || compare(line, module4, (mycolor+1)%2, j)
|| compare(line, module5, (mycolor+1)%2, j) || compare(line, module6, (mycolor+1)%2, j)){
result -= WEIGHT3;
j+=module3.length;
continue;
}
}
if(compare(line, module7, (mycolor+1)%2, j) || compare(line, module8, (mycolor+1)%2, j)
|| compare(line, module9, (mycolor+1)%2, j) || compare(line, module10, (mycolor+1)%2, j)
|| compare(line, module11, (mycolor+1)%2, j)){
result -= WEIGHT3;
j+=module7.length;
continue;
}
if(j<line.length-5){
if(compare(line, module12, (mycolor+1)%2, j) || compare(line, module13, (mycolor+1)%2, j)
|| compare(line, module14, (mycolor+1)%2, j)){
result -= WEIGHT4;
j+=module12.length;
continue;
}
if(compare(line, module15, (mycolor+1)%2, j) || compare(line, module16, (mycolor+1)%2, j)){
result -= WEIGHT5;
j+=module15.length;
continue;
}
}
j++;
}
return result;
}
private int heng(int [][]a, int color) {
int heng = 0;
for(int i=0;i<15;i++){
int row[] = new int[15];
for(int j=0;j<15;j++) row[j] = a[i][j];
heng += calculate_line(row, color);
}
return heng;
}
private int shu(int [][]a, int color) {
int shu = 0;
for(int i=0;i<15;i++){
int column[] = new int[15];
for(int j=0;j<15;j++) column[j] = a[j][i];
shu += calculate_line(column, color);
}
return shu;
}
private int pie(int [][]a, int color) {
int pie = 0;
for(int i=4;i<14;i++){
int line1[] = new int[i+1];
for(int j=0;j<i+1;j++) line1[j] = a[i-j][j];
pie += calculate_line(line1, color);
int line2[] = new int[i+1];
for(int j=0;j<i+1;j++) line2[j] = a[14-i+j][14-j];
pie += calculate_line(line2, color);
}
int line1[] = new int[15];
for(int j=0;j<15;j++) line1[j] = a[14-j][j];
pie += calculate_line(line1, color);
return pie;
}
private int na(int [][]a, int color) {
int na = 0;
int line[] = new int[15];
for(int j=0;j<15;j++) line[j] = a[j][j];
na += calculate_line(line, color);
for(int i=1;i<11;i++){
int line1[] = new int[15-i];
for(int j=0;j<15-i;j++) line1[j] = a[i+j][j];
na += calculate_line(line1, color);
int line2[] = new int[15-i];
for(int j=0;j<15-i;j++) line2[j] = a[14-i-j][14-j];
na += calculate_line(line2, color);
}
return na;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -