4

私は、いくつかのインゲーム コンピューター ステアード プレーヤーでいくつかの単純な AI 実装を使用して単純なゲームを作成しています。

Pointプレイヤーの可能な動きを表すリストがあります。Pointそのリスト内の敵から最も離れた場所にプレイヤーを移動させるメソッドを作成する必要があります。私はそれを絵で説明しました:

数字はリスト内のポイントの位置を表します

私が望むのは、プレイヤー (4) がPoint敵から最も離れた位置 2 または 6 に移動することです。リストを反復し、どのポイントが最も離れているかを判断するdistance()方法を使用して、敵が 1 人いる場合、これを解決することができました。Pointただし、グリッド内に複数の敵がいる場合でも、コードは機能する必要があります。

4

1 に答える 1

1

うーん、逆にどうですか?

1. Iterate over each point.
2. Find out how close it is to its closest enemy.
3. Choose the point that is furthest from its closest enemy.

アーリーアウトには多くの可能性があります。

Within the loop store the currently furthest point. 
If you are then inspecting another point and find out
it has a closer enemy, you can immediately skip to the
next point

[編集]: また、上記のようにグリッドを使用している場合は、次のことができます

1. Check if there's an enemy on the currently processed 
   point *before* iterating through other enemies. That way
   you can exclude it as early as possible.

2. If it's a densely populated grid, consider doing a breadth-first
   flood-fill starting at the current point. That might find the closest
   enemy much faster than iterating though all of them.
于 2012-07-18T09:31:27.230 に答える