* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package 演算法;
/**
*橫向存點
垂直存點
觸發點
每格都如此
往右邊走
如果 碰到相同
Save 橫向存點
如果 到邊界 或是 不相同
return
回到觸發點
往左邊走
如果 碰到相同
Save 橫向存點
如果 到邊界 或是 不相同
return
回到觸發點
往上邊走
如果 碰到相同
Save 垂直存點
如果 到邊界 或是 不相同
return
回到觸發點
往下邊走
如果 碰到相同
Save 垂直存點
如果 到邊界 或是 不相同
return
完成計算需要消除的點
清空除存點
* @author howard
*/
public class 三消演算dfs_1 {
static int[][] directArrays = {{0,1},
{0,-1},
{-1,0},
{1,0}};
static int[][] threeMatch={
{0,0,0,0,0,0},
{0,0,1,0,0,0},
{1,1,1,0,0,0},
{0,0,1,0,0,0},
{0,0,1,0,0,0}
};
public static void triggerPoint(int x,int y){
for (int i = 0;i<directArrays.length;i++){
int[] direct = directArrays[i];
int nextX = x + direct[0];
int nextY = y + direct[1];
int matchNumber = threeMatch[x][y];
nextPoint(matchNumber,nextX,nextY,direct);
}
}
public static void nextPoint(int matchNumber, int nextX,int nextY,int[] direct){
if (nextX < 0 || nextX == threeMatch.length ||
nextY < 0 || nextY == threeMatch[0].length ||
threeMatch[nextX][nextY] != matchNumber){
System.out.println("=======================");
return;
}
System.out.println("X:"+nextX+"Y:"+nextY);
nextX += direct[0];
nextY += direct[1];
nextPoint(matchNumber,nextX,nextY,direct);
}
public static void main(String[] args) {
triggerPoint(2,2);
}
}
沒有留言:
張貼留言