robocode引擎:如何设计(编写)运行时引擎——机器人世界

发布于 2024-08-17 14:15:11 字数 314 浏览 1 评论 0原文

IBM 有一个名为 RoboCode 的免费学习 Java 程序,可以在其中编写自定义机器人,然后在 2D 空间中进行战斗。我想编写支持此类机器人的环境,但不知道使用什么模式或设计。每个机器人都是一个线程。 JRE 为每个线程提供一定的(不确定的)运行时间。机器人世界引擎将首先构建玩家/机器人列表,然后进入一个循环,允许每个玩家轮流做自己喜欢的事情:向前移动、向左转、向西北角开火等等。每个机器人也会被告知感兴趣的事件:一个或多个敌人在射程内,它被子弹击中等等。同时也是

事件侦听器的处理线程的组合(它们也是生产者吗?)让我感到困惑;游戏引擎似乎还有更多内容。即使是一些一般性的想法也会有所帮助。

IBM has (had) a free learn-Java program called RoboCode, in which custom robots could be written that would then do battle in a 2D space. I would like to write the environment that supports such robots, but don't know what pattern or design to use. Each robot is a thread. Each thread is given a certain (indeterminate) amount of run-time by the JRE. A robot world engine would start by building a list of the players/robots, then enter a loop that allows each player in turn to do whatever it likes: move forward, turn left, fire toward the northwest corner, whatever. Each robot is also informed of events of interest: an enemy or several enemies are within range, it has been hit by a bullet, etc.

The combination of handling threads that are also event listeners (are they also producers?) confuses me; it seems that there's more to the game engine. Even some general ideas would help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在夏天 2024-08-24 14:15:11

我是 Robocode 引擎开发人员。我2年前加入,大部分时间都花在重构Robocode引擎上。根据我的理解,我在那段时间写了几篇文章长大了。我想,并非所有这些都是最新的。

它有几个困难的部分:

1)同步:我们通过在机器人和战斗之间“发送”消息来解决它。更新 UI 和其他组件是生产者/消费者,使用有关每个新状态(游戏刻度)的不可变消息

2) 沙箱恶意代码(从我们的代码中学习)

3) API 和规则的设计可以长期保持不变,由于引擎不断发展,旧机器人保持不变,但它们必须以与以前相同的方式运行和得分。我们在这里遇到了一些麻烦,例如人们按照自己的逻辑使用 API 中的类。这不是故意的。我们必须将类设为最终类并使用受保护的构造函数。但现在我们无法改变它以不破坏现有的机器人。

对于您关于 Robocode 中的事件的问题。它们每次都会出现,我们填充 EventManager(优先级队列),然后机器人一一拉动。每个事件的调用都会分派回机器人的实现。订阅是自动的,实现始终存在于基类中,您可以在机器人类中覆盖它。机器人有单线程。

顺便说一句:下一件大事似乎是 Robocode 的扩展,以允许自定义/可插入规则。这是设计挑战。我们正在寻找聪明、勤奋的人才加入 Robocode 项目来帮助我们。感兴趣的 ?

I'm Robocode engine developer. I joined 2 years ago and spent most of the time by refactoring Robocode engine. I wrote couple of articles during the time as my understanding grown. Not all of them are up to date, thought.

There are several difficult parts about it:

1) synchronization: we solved it by 'sending' messages between robot and battle. Updating the UI and other components is producer/consumer with non-mutable messages about each new state (game tick)

2) sandboxing malicious code (go and learn from our code)

3) design of API and rules to be constant for long years, because engine evolves, old robots stay same, but they must run and score same way as before. We hit several troubles here, for example people use the classes from API in their own logic. This wasn't intention. We had to make the classes final and with protected constructors. But now we can't change it to not broke existing robots.

For your question about events in Robocode. They all come each tick, we populate EventManager (priority queue) and then robot pulls one by one. Call is dispatched back to robot's implementation for each event. The subscription is automatic, implementation is always present in base class and you could override it in robot class. There is single thread for robot.

BTW: Next big thing seems to be extension of Robocode to allow for custom/plugable rules. It's design challenge. We are looking for smart, hard working people to join Robocode project to help us. Interested ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文