模拟异步游戏环境
这个想法是为代理建立一个环境模型。在最基本的情况下,它看起来像这样:
- 系统要求代理执行下一步操作
- 代理响应(例如“向左移动!”)
- 系统将代理移动到适当的状态
但是,我在以异步方式实现这一点时遇到了麻烦(使用线程等)。
目前我的系统看起来像这样:
void Start(){
while(true && !gameOver){
askAgent()
moveAgent()
if(agentState == terminalState){
gameOver = True;
}
}
}
显然,这会阻塞正在运行的线程。 (更尴尬的是我正在使用 OSGi,所以任何单个包都不应该占用所有处理时间!)
另外,我希望系统能够对环境中出现的新代理做出反应,并与它们交互(我的运行时,OSGi ,已经具备了在系统中出现或消失某些内容时通知我的功能),例如:
void setAgent(Agent agent){
system.addAgentToEnvironment(agent);
system.simulateAgent(agent);
}
而不是直接从 main 运行...
我知道这非常令人困惑,而且我不确定我是否提出了这个问题正确 - 所以任何我非常感谢有关我可以查看的架构或方法的建议。
The idea is to model an environment for agents. In the most basic case it looks likes this:
- System asks the agent for the next action
- Agent responds (e.g. "move left!")
- System moves the agent to the appropriate state
However, I am having trouble implementing this in an asynchronous manner (with threading and such).
Currently my system looks like this:
void Start(){
while(true && !gameOver){
askAgent()
moveAgent()
if(agentState == terminalState){
gameOver = True;
}
}
}
Clearly, this blocks the thread this is running on.
(What's more embarrassing is I am using OSGi, so any single bundle should not be hogging all the processing time!)
Also, I would like the system to react to new agents appearing in the environment, and engage with them (my runtime, OSGi, already has the facility of notifying me if something appears or disappears from the system) something like:
void setAgent(Agent agent){
system.addAgentToEnvironment(agent);
system.simulateAgent(agent);
}
Instead of just running from main straight away...
I know this is very confusing, and I am not sure if I am even posing the question correctly - so any tips on the architecture or approaches I can look at are greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您肯定需要一些数据保护(可能在代理主列表上,以及对每个单独代理及其数据的某种保护)。
除此之外,我会遵循这种模型:
HTH
You will definitely need some data protection (perhaps on a master list of agents, and some kind of protection on each individual agent and its data).
Other than that, I would follow this kind of model:
HTH
为了帮助思考应用程序的未来,我强烈建议您使用两个循环。
这个片段给了你两件事。
filterFor(Environment e, Agent a)
来为该特定代理制作环境的模拟版本。比如戴醉酒护目镜或眼罩之类的。In order to help think about the future of the application, I would urge you to use two loops.
This snippet gives you two things.
filterFor(Environment e, Agent a)
that makes a mocked up version of the environment for that particular agent. Like wearing drunk-goggles or a blindfold or something.