# 尋找如何重構我的算法的想法

ForceAppliedToACell http://img293.imageshack.us/img293/2852/29186643.png</一>

Forces from lower left neighbour: down (0), up (2), right (2), left (0)
Forces from right neighbour     : down (0), up (0), right (0), left (2)
sum                             : down (0), up (2), right (0), left (0)


• 到達應作為參數傳遞
• 我想改變函數，它計算力（潛力，斐波那契）
• 只有在未填充此新地點時，單元格才能轉到新地點
• 註意角落（例如，您無法評估右上角的右鄰居和頂級鄰居）

## 最佳答案

Here is some rough code written in pseudo-Java showing the basic ideas: http://codepad.org/K6zxnOAx

enum Direction {Left, Right, Up, Down, None};

Direction push(boolean board[][], int testX, int testY, int reach)
{
int xWeight = 0;
int yWeight = 0;
for (int xDist=-reach; xDist<=+reach; ++xDist)
{
for (int yDist=-reach; yDist<=+reach; ++yDist)
{
int normDist = abs(xDist) + abs(yDist);
if (0<=x && x<=y && y abs(yWeight))
{
return xWeight<0 ? Direction.Left : Direction.Right;
}
else
{
return yWeight<0 ? Direction.Up : Direction.Down;
}
}

int getForceMagnitude(int reach, int distance)
{
return 1<<(reach-distance);
}