2012-07-18 4 views
4

일부 ingame 컴퓨터 steerd 플레이어에서 간단한 AI 구현으로 간단한 게임을 만들고 있습니다.다른 지점의 멀리 떨어진 지점을 결정하십시오

플레이어의 가능한 동작을 나타내는 Point 목록이 있습니다. 그 플레이어를 그리스트에있는 가능한 적에게서 가장 멀리 떨어진 Point으로 이동시키는 방법을 써야합니다.

번호 목록에서 poistion이

내가 원하는 것은 선수입니다 포인트 (4) 멀리 멀리있는 위치 2 또는 6 중 Point로 이동 대표 : 나는 사진과 삽화가 어떤 적. 나는 목록을 반복하고 distance() 방법을 사용하여 Point의 적을 하나만 남겨두면 어느 지점이 가장 멀리 떨어져 있는지를 판단 할 수있었습니다. 그러나 코드는 그리드에 여러 개의 적들이 있더라도 작동해야합니다.

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. 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. 

초기 아웃 가능성이 많이있다 : 당신이 그것을 라운드 다른 방법을 대한

+0

그래서 작동 했나요? – HumanCatfood

답변

1

흠, 어떻게 또한 작동하는 경우 위와 같이 그리드로,

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. 
+0

또한 : 재미있는 다이어그램에 투표하세요! – HumanCatfood

관련 문제