尻尾の位置を簡単に追う方法はありますか?可能であれば、頭の目標を尻尾の位置と等しくなるように設定できます。尻尾の位置を簡単にマークできない場合は、より複雑になります。
ヘビの長さがわかっていて(ヘビは正確snakeLength
なサイズの長方形のパスをたどることができるので、そうしていると思います)、それが長方形であれば、endOfGame==trueまでループし続ける状態に入ることができるはずです。 、 例えば。
divSnakeLength = snakeLength / 4; (giving you the length of each side of the rectangle)
distanceToApple = divSnakeLength / 2;
applePosition = this.getApplePosition();
Position[] rectangleEdges = new int[2][2];
rectangleEdges[0] = {applePosition.x - distanceToApple,
applePosition.y + distanceToApple};
rectangleEdges[1] = {applePosition.x + distanceToApple,
applePosition.y + distanceToApple};
rectangleEdges[2] = {applePosition.x + distanceToApple,
applePosition.y - distanceToApple};
rectangleEdges[3] = {applePosition.x - distanceToApple,
applePosition.y - distanceToApple};
//now we have the four corners of the rectangle
while(!endOfGame){
foundGoal = false;
setGoal(rectangleEdges[0]);
while(!foundGoal(rectangleEdges[0]));
setGoal(rectangleEdges[1]);
while(!foundGoal(rectangleEdges[1]));
setGoal(rectangleEdges[2]);
while(!foundGoal(rectangleEdges[2]));
setGoal(rectangleEdges[3]);
while(!foundGoal(rectangleEdges[3]));
}
私はあなたがあなたの途中であなたを少しずつ動かすことを願っています。