back_recharge
parent
4dd64f4237
commit
51257cda85
|
|
@ -24,24 +24,11 @@ public class CellUtil {
|
|||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int xx = 9;
|
||||
int yy = 19;
|
||||
int xx = 2;
|
||||
int yy = 2;
|
||||
xy2Pos(xx,yy);
|
||||
|
||||
System.out.println(getSurroundPos(10,20,xy2Pos(xx,yy)));
|
||||
// int pos = xy2Pos(xx,yy);
|
||||
// System.out.println("======> pos : "+pos);
|
||||
// int[] xy = pos2XY(pos);
|
||||
// System.out.println("=======> nX : "+xy[0]+" , nY : "+xy[1]);
|
||||
// System.out.println("=====================================");
|
||||
// Set<Integer> cells = getOneOpenCell(21,18, pos);
|
||||
// for(Integer i : cells){
|
||||
// int[] new_xy = pos2XY(i);
|
||||
// System.out.println("=======> nX : "+new_xy[0]+" , nY : "+new_xy[1]);
|
||||
// }
|
||||
//
|
||||
// System.out.println(pos2XY(520)[0]);
|
||||
// System.out.println(pos2XY(520)[1]);
|
||||
System.out.println(getSurroundPos(3,3,xy2Pos(xx,yy)));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -86,71 +73,31 @@ public class CellUtil {
|
|||
System.out.println("=====================================");
|
||||
return openCells;
|
||||
}
|
||||
// int width,int height ,
|
||||
|
||||
public static Set<Integer> getSurroundPos(int width,int height ,int pos){
|
||||
Set<Integer> poses = new HashSet<>();
|
||||
// int width = 10;
|
||||
// int height = 10;
|
||||
int [] xy = pos2XY(pos);
|
||||
int x = xy[0];
|
||||
int y = xy[1];
|
||||
|
||||
if(x==1){
|
||||
if(y==1){
|
||||
poses.add(xy2Pos(x,y+1));
|
||||
int x1=x-1;
|
||||
int y1=y-1;
|
||||
for(;x1<x+2;x1++){
|
||||
if(x1<1 || x1 > width){
|
||||
continue;
|
||||
}
|
||||
else if(y==height){
|
||||
poses.add(xy2Pos(x,y-1));
|
||||
}else{
|
||||
poses.add(xy2Pos(x,y+1));
|
||||
poses.add(xy2Pos(x,y-1));
|
||||
for(;y1<x+2;y1++){
|
||||
if(y1<1 || y1 > height){
|
||||
continue;
|
||||
}
|
||||
poses.add(xy2Pos(x+1,y));
|
||||
return poses;
|
||||
}else if(x==width){
|
||||
if(y==1){
|
||||
poses.add(xy2Pos(x,y+1));
|
||||
}else if(y==height){
|
||||
poses.add(xy2Pos(x,y-1));
|
||||
}else{
|
||||
poses.add(xy2Pos(x,y+1));
|
||||
poses.add(xy2Pos(x,y-1));
|
||||
if(x1 == x && y1 == y){
|
||||
continue;
|
||||
}
|
||||
poses.add(xy2Pos(x-1,y));
|
||||
return poses;
|
||||
System.out.println("x ->" + x1 + " y->" + y1);
|
||||
poses.add(xy2Pos(x1,y1));
|
||||
}
|
||||
|
||||
if(y==1){
|
||||
if(x==1){
|
||||
poses.add(xy2Pos(x+1,y));
|
||||
y1=y-1;
|
||||
}
|
||||
else if(x==width){
|
||||
poses.add(xy2Pos(x-1,y));
|
||||
}else{
|
||||
poses.add(xy2Pos(x+1,y));
|
||||
poses.add(xy2Pos(x-1,y));
|
||||
}
|
||||
poses.add(xy2Pos(x,y+1));
|
||||
return poses;
|
||||
}else if(y==height){
|
||||
if(x==1){
|
||||
poses.add(xy2Pos(x+1,y));
|
||||
}else if(x==width){
|
||||
poses.add(xy2Pos(x-1,y));
|
||||
}else{
|
||||
poses.add(xy2Pos(x+1,y));
|
||||
poses.add(xy2Pos(x-1,y));
|
||||
}
|
||||
poses.add(xy2Pos(x,y-1));
|
||||
return poses;
|
||||
}
|
||||
|
||||
|
||||
poses.add(xy2Pos(x+1,y));
|
||||
poses.add(xy2Pos(x-1,y));
|
||||
poses.add(xy2Pos(x,y+1));
|
||||
poses.add(xy2Pos(x,y-1));
|
||||
|
||||
return poses;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue