有没有办法构造一个函数来获取存在于多个上层代理中的子代理的主要坐标?

Is there a way to construct a single function to get the coordinates in main of a sub-agent that is present in multiple upper-level agents?

当一个代理是多个其他代理的下级代理时,是否有一种直接的方法来获取该代理相对于 main 的坐标点?

例如:

我有一个 Box 代理。 我的 ShelfPallet 代理中都有 Box 个代理,Pallet 个代理可以位于 mainRack 特工。

所以我有:

main > Shelf > Box

main > Pallet > Box

main > Rack > Pallet > Box

到目前为止,我已经创建了单独的硬编码函数,将 Box 的坐标与其上层代理的坐标相加。

所以:

对于货架托盘中的箱子:CoordBoxInMain = CoordBox + CoordPallet + CoordRack

对于货架上的盒子:CoordBoxInMain = CoordBox + CoordShelf

但现在我想知道,有没有一种方法可以构造一个函数来直接获取我的 Box 代理的坐标,而不必创建多个不同的函数,每个函数都引用不同的 upper-一级特工?

谢谢。

你可以使用这段小代码

Agent agent = myBox;
double xCoord = agent.getX();
while (agent.getOwner() != null) {
    xCoord += agent.getOwner().getX();
    agent = agent.getOwner();
}

traceln(xCoord);

它将继续寻找代理的所有者,直到它到达主(或您的根代理)并添加 X 坐标,然后跟踪它

你也需要对 Y 和 Z 做同样的事情

我在一个简单的模型上对其进行了测试并且它有效