0

我先把我的伪代码放在这里,请根据现实世界的行人运动建议它的有效性,以及如何改进它。

前提:一只乌龟从它的出生点走到目标。在途中,它遇到了其他乌龟。相同颜色的海龟将被视为“伙伴”,并会靠近它,模拟“朋友-走在街上”的场景。距离较近的同色海龟优先级较高,例如朋友 A 比朋友 B 更近,所以我会先接近朋友 A。

接近目标后,海龟会返回其生成点。

伪代码:

determine if i am already in the goal
if yes,
    determine if there are patches I can walk on
    set eyes on nearest patch I can walk on (for the goal path)
    if there is a friend nearby, approach friend
    if there is no friend nearby, continue walking the goal path
    if im already in the goal, respawn.

请建议改进​​?

4

1 回答 1

1

前提没有说明如何返回生成点,因此我假设这是一步操作(即您对这些细节不感兴趣)。我看到了更多类似的东西

spawn loop: 
  spawn
  goal loop: 
    determine if turtle already reached goal
    if no,
      determine if there are patches I can walk on
      set eyes on nearest patch I can walk on (for the goal path)
      if there is a friend nearby, approach friend
      if there is no friend nearby, continue walking the goal path
    if yes, 
      setup so can respawn (return to spawn loc, etc)
      goal loop ends
于 2013-12-23T14:07:27.607 回答