使用 .Net 开发 Robocode 类型的游戏,用于学校作业

发布于 2024-07-13 00:37:32 字数 2994 浏览 6 评论 0原文

我目前正在学校的最后一年,正在攻读计算机研究国家高级文凭,基本上在最后一个学期,我们需要开发一个软件项目,它基本上包含一个整个系统。

现在,我想做的是类似于 Robocode 的事情,但我不是使用 Java,而是使用 Java将使用 .Net Framework 来完成此操作。


什么是机器人代码?

对于那些不知道 Robocode 是什么的人来说,它基本上是一种编程游戏,人们使用现有的类接口和可下载类中的方法开发自己的机器人,然后它们互相战斗。其他在竞技场的自主战斗中......就像这样:

替代文字
(来源:com.com


所以基本上,正如我所说,我想使用 .Net Framework 重新创建这种场景。我将这个问题发布在 StackOverflow 上,希望更有经验的开发人员能够正确指导我该项目的方向。

到目前为止,我的想法基本上是创建:

  • 一个离线应用程序,它将作为战场和用户界面,以与现有机器人等创建新的战斗。
  • 玩家可以使用在线界面来注册新机器人、查看过去的锦标赛得分等……
  • 显然,玩家需要使用职业界面来创建机器人。

动画和图形(用于实际战斗)

现在,当然,战斗发生时会有某种动画和动作,但我还没有决定使用什么作为媒介。

我目前想到的选项是:

  • 正如我在上面第一个要点中所说,开发一个离线应用程序,作为战场,所有动画将主要使用 C# 代码完成,
  • 或者开发一个 Silverlight 应用程序来处理动画(因此,将场景从离线应用程序更改为现在的在线应用程序
  • ,或者,也许是其中最不可行的方法,使用 JavaScript 创建战斗动画,例如 Canvas

您认为什么更适合这种特定场景?


类和接口

对于开发机器人的玩家,我将提供某些类接口,他们将能够像在 Robocode 中一样使用

这些事件和方法的示例:

public void run () {}
public void onScannedRobot(ScannedRobotEvent e) {}

walk(/* ammount in pixels or w/e to walk to */);
turnRight(/* value in degrees for an angular turn */);
//etc...

以下是 Robocode 中的代码片段(Java)。 ):

public class MyFirstRobot extends Robot {
    public void run() {
        while (true) {
             ahead(100);
             turnGunRight(360);
             back(100);
             turnGunRight(360);
         }
    }
}

为了让战斗真正发生,我正在考虑使用反射来实际读取用户实际使用的方法,并实现它们在战斗的特定时刻运行和调用。


现在,我善意而谦虚地请求你们经验丰富的开发人员,指导我完成我的这个项目,并就需要做什么提供建议......对于初学者来说,这个项目在全部?如果确实如此,我需要从哪里开始我的项目?


至于我打算的技术和软件使用的是:

  • .NET Framework 3.5,带有 C# 3.0
  • LINQ(语言集成查询)
  • SQL Server 2008
  • Microsoft Visual Studio 2008
  • jQuery Framework
  • 可能 Silverlight

我感谢大家,即使是在我的问题中设法阅读到这一点,我也需要并非常感谢我为完成这个项目所能得到的所有帮助。

感谢您的时间和精力。


顺便说一句,到目前为止,除了 Robocode 之外,我还发现了这些与我正在尝试的游戏类似的游戏创建:

  • NRobot
  • < a href="https://vrs-net.sourceforge.net/" rel="nofollow noreferrer">Virii (感谢 马克

I am currently in my final year at school, studying for a Higher National Diploma in Computer Studies, and basically in this final semester, we need to develop a Software Project, that basically incorporates a whole system.

Now, what I'm thinking of doing is something along the lines of Robocode, but instead of Java, I will be doing this with the .Net Framework.


What is Robocode ?

For those of you don't know what Robocode is, it's basically a sort of programming game in where people develop their own robots using methods from the class interfaces and downloadable classes that exist, and then they fight each other in an autonomous battle in an arena...like such:

alt text
(source: com.com)


So basically, as I said, I want to recreate this sort of scenario using the .Net Framework..and I am posting this question here on StackOverflow in hope that more experienced developers will be able to guide me in the right direction for this project.

What I have in mind up till now is basically to create:

  • An Offline application that will serve as the battle arena and the user-interface to create new battles with existing robots and such.
  • An Online interface that players will able to use to register new robots, view past tournament scores etc...
  • And obviously the Class Interfaces that players will need to use to create their robots.

Animation and Graphics (for the actual battles)

Now, of course there will be some sort of animation and movement when the battle occurs, and I haven't decided what yet to use as a medium for this.

The options I currently have in mind are:

  • Developing, as I said in the first above bullet points, an offline application that will serve as a battle grounds, and all animations will be done using mainly C# code
  • Or develop a Silverlight Application that will handle the animations (thus, changing the scenario from an offline applcation to now an online one
  • Or, maybe the least feasable of them, create the battle animations using JavaScript, with something like the Canvas

What do you think could be more suitable for this particular scenario ?


Developing Classes and Interfaces

For the players to develop the robots, I will provide certain Class Interfaces that they will be able to use like in Robocode.

Examples of such events and methods may include:

public void run () {}
public void onScannedRobot(ScannedRobotEvent e) {}

walk(/* ammount in pixels or w/e to walk to */);
turnRight(/* value in degrees for an angular turn */);
//etc...

Here is a snippet from code in Robocode (Java) :

public class MyFirstRobot extends Robot {
    public void run() {
        while (true) {
             ahead(100);
             turnGunRight(360);
             back(100);
             turnGunRight(360);
         }
    }
}

For then to actually make the battles happen, I am thinking of using Reflection to actually read what methods the user is actually making use of and implementing them to run and be invoked at particular moments of the battle and such.


Now, what I kindly and humbly ask of you experienced developers, is to guide me a bit through this project of mine and advise me on what needs to be done...for starters, is this project feasible at all ? And if it actually is, from where do I need to actually start with my project?


As regards technologies and software I intend to be using are :

  • .NET Framework 3.5, with C# 3.0
  • LINQ (Language Integrated Query)
  • SQL Server 2008
  • Microsoft Visual Studio 2008
  • jQuery Framework
  • Possibly Silverlight

I thank you all, even for managing to read up to this point in my question and I will need and appreciate greatly all the help I can get to finish this project.

Thank you for your time and effort.


Btw, up till now, apart from Robocode, I have found these games that are similar to what I am trying to create:

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

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

发布评论

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

评论(6

旧人 2024-07-20 00:37:33

当我开始使用 WPF(与 Silverlight 非常相似)时,我最终花了很多时间来弄清楚如何做事。 与我尝试过的其他方法相比,这是一种非常不同的制作 GUI 的方法,而且似乎有十亿种不同的方法可以做事。 我的观点是,如果您没有 WPF/Silverlight 的经验,我怀疑您需要花费很多时间来理清思路。 我想这取决于你已经知道的事情。

除此之外,我完全支持ChrisW关于增量开发的建议。 我将向您介绍如何进行游戏设计。 从一个非常简单的机器人 API 开始,比如说两个没有事件、输入或世界知识的函数。 首先让机器人移动。 关键是要获得一个功能齐全、功能简单的程序,包括从加载客户端代码到显示“战斗”结果的所有部分。

每个机器人都应该使用单个方法 run() 实现一个接口,并位于自己的 dll 文件中。 当战斗开始时,每个实现了接口的dll都会从某个位置加载(使用反射)并实例化。 然后循环开始战斗,直到 1 分钟过去(或者其他什么,只是为了看看正在发生什么事情):

while (time is not up)
   generate random sequence for bots
   call run() on each bot
   draw(world)

时间到了,战斗就结束了。 现在您有了一个框架应用程序,您可以开始充实它,并且即使您没有时间实现您想要的所有功能,它也可以让您拥有一个工作程序。 在 run 方法中,机器人可以调用您在 API 中定义的几个移动操作。 调用这些将改变世界的状态 - 可能只是一个图块网格,以及每个机器人的位置。

下一步可能是向机器人的 run 方法添加世界视图,将循环更改为:

while (time is not up)
   generate random sequence for bots
   call run(WorldView) on each bot
   draw(world)

假设机器人仍然只能在其 run 方法中执行几个移动操作。 现在,他们可以选择了解世界(或他们的一部分),这使他们能够靠近或远离敌人并避开墙壁。

在下一次迭代中,您可以创建一个 API 函数来发射大炮(或任何适合您游戏的内容)。 实现如何改变世界状态、如何跟踪子弹以及如何表示动画等。循环可能看起来像这样:

while (time is not up and there are more than 1 bot alive)
   advance projectiles
   calculate projectile-bot collisions and damage
   generate random sequence for bots
   call run(WorldView) on each bot
   draw(world)

我希望这能让您了解如何始终迭代地充实程序有一个反映游戏所有领域的工作程序。 我在实现游戏方面没有太多经验,所以你应该以批判的眼光看待我的建议,但这就是我解决问题的方法。

When I began working with WPF (which is much the same as Silverlight) I ended up spending a lot of time figuring out how to do things. It is a very different way of making a GUI than what else I've tried and there seems to be a billion different ways to do things. My point is, that if you have no experience with WPF/Silverlight I suspect it is going to take a lot of time for you to wrap your mind around. I guess it depends on what you already know.

Apart from than, I wholeheartedly support ChrisW's suggstion about incremental development. I'll give you an idea of how you can approach the design of the game. Start out with a very simple API for the bots, say two functions with no events, input or knowledge of the world. Just start by getting the bots to move. The point is to get a fully functioning program with the simple functionality, including all parts from loading the client code to showing the resulting 'battle'.

Each bot should implement an interface with a single method run() and be in their own dll file. When the battle starts, each dll with the interface implemented is loaded (using reflection) from a certain location and instantiated. Then start a battle with a loop until 1 minute has passed (or whatever, just to see that something is going on):

while (time is not up)
   generate random sequence for bots
   call run() on each bot
   draw(world)

When the time is up, the battle is over. Now you have a skeleton application which you can begin to flesh out and which will let you have a working program, even if you won't have time to make all the functionality you would like. In the run method, the bots can call the couple of move actions you have defined in the API. Calling these will change the state of the world - probably just a grid of tiles, and the location of each bot.

The next step could be to add a view of the world to the bots' run method, changing the loop to this:

while (time is not up)
   generate random sequence for bots
   call run(WorldView) on each bot
   draw(world)

Let's say that the bots can still only perform a couple of move actions in their run method. Now they have the option of getting a view of the world (or their part of it) which allows them to move towards or away from enemies and avoid walls.

In the next iteration you could then create a single API function to shoot you cannon (or whatever is appropriate your game). Implement how this changes the world state, how the bullets are tracked and how the animation is represented, etc. The loop could look something like this:

while (time is not up and there are more than 1 bot alive)
   advance projectiles
   calculate projectile-bot collisions and damage
   generate random sequence for bots
   call run(WorldView) on each bot
   draw(world)

I hope this gives you an idea of how you can iteratively flesh out the program, all the while having a working program that reflects all the areas of the game. I don't have much experience with implementing games, so you should look at my advice with a critical eye but this is how I would attack the problem.

烟雨扶苏 2024-07-20 00:37:33

这是非常可行的。

我建议从响应“编译”机器人代码的后端系统和对象开始。 “编译”代码采用什么形式取决于你。

然后,为 robocode 创建解释器。 或者,听起来您可能只能创建 .NET 类。 这是最难的部分的免费赠品。

最后,创建您可能需要的任何 UI...一切就绪。

您可能希望将机器人编译为 .dll ...尽管如此,您只需为它们创建通用接口和功能即可。

It's very feasible.

I suggest starting with the back-end system and objects that respond to "compiled" robocode. What form that "compiled" code takes is all you.

Then, create the interpreter for the robocode. Or, it sounds like you might just be able to make the .NET classes. That's a freebie on the hardest part.

Finally, create any UI you might require...all set.

You might want to have the robots compile as .dlls ...nonetheless, you just have to create the common interface for them, and functionality.

我爱人 2024-07-20 00:37:33

可行性完全取决于你的团队的能力、对框架的熟悉程度等。我见过有人能在一周内完成这样的事情,也见过有人做不到以挽救自己的生命。

你提到的反思方法听起来像是错误的轨道,除非我误解了你。 您的“机器人”基类应该允许开发人员重写一个或多个方法,他们可以从中调用“射击”、“移动”等函数。

另一个与此类似的应用程序是 Terrarium。 开发人员可以对动物进行编码,并让它们在分布式环境中与其他动物进行竞争。 它是一个 .NET 1.1 演示应用程序,有点过时,但其中一些原理可能仍然对您有帮助。 这个人已经开始重写它:
http: //weblogs.asp.net/bsimser/archive/2008/07/16/reintroducing-terrarium-now-with-2-0-goodness.aspx

feasibility totally depends on your team's ability, familiarity with the framework, etc. I've seen people who could knock something like this out in a week, and others who couldn't do it to save their lives.

The reflection approach you mention sounds like the wrong track, unless I'm misunderstanding you. Your 'Robot' base class should allow developers to override one or more methods, from which they can call functions like 'Shoot', 'Move', etc..

One other app that was similar to this is Terrarium. Developers could code animals and pit them against others in a distributed environment. It was a .NET 1.1 demo app, and is a bit dated, but some of the principals may still be helpful to you. This guy has taken on rewriting it:
http://weblogs.asp.net/bsimser/archive/2008/07/16/reintroducing-terrarium-now-with-2-0-goodness.aspx

岁月染过的梦 2024-07-20 00:37:33

那么,有点像 virii 吗?

So, kinda like virii, then?

十雾 2024-07-20 00:37:33

Real Robocode 很快就会获得用于运行 .NET 机器人的插件。
我花了两年时间才实现这一目标。 第一年用于重构原始 Robocode。 第二个是 Java 到 .NET 桥。 还有 alpha 位。 这种方法的好处是你可以与最好的 Java 机器人战斗。 机器人里其实蕴藏着巨大的宝藏。

Real Robocode will get plugin for running .NET robots soon.
It took me 2 years to achieve that. First year spent on refactoring original Robocode. Second one on Java to .NET bridge. And there are the alpha bits. This approach has benefit that you could fight with best Java robots. There is big treasure in the robots actually.

〃温暖了心ぐ 2024-07-20 00:37:32

这个项目是否可行?

听起来很大。 我不知道你还有多少时间。 以下是一条经验法则:

  • 当截止日期到来时,如果提供 90% 功能的系统 90% 已 100% 完成,那么您可能会说该项目至少 90% 成功。

  • OTOH,如果提供 100% 功能的软件的 100% 仅完成了 90%(即,未完成),那么什么都没有完成,项目就会失败。

那么,成功的关键是“增量开发”和“持续交付”。 您的项目规范说:

我们需要开发一个软件项目,它基本上包含一个整个系统。

为此,我建议:

  1. 创建(即设计、开发和测试)一个小型整体系统
  2. 重复{备份或版本控制您所拥有的; 向系统添加一个新的、完整的一点,并测试它直到满意为止}直到(你用完时间)。

is this project feasible at all ?

It sounds big. I don't know how much time you have. Here's a rule of thumb:

  • When the drop-dead due-date happens, if 90% of the system delivering 90% of the functionality is 100% complete, then you might say that the project is at least 90% successful.

  • OTOH if 100% of the software delivering 100% of the functionality is only 90% finished (i.e., is not finished) then nothing is finished and the project is a failure.

A key to success, then, is "incremental development" and "continual delivery". Your project specification says:

We need to develop a Software Project, that basically incorporates a whole system.

To do this, I suggest:

  1. Create (i.e., design, develop, and test) a small whole system
  2. Repeat { backup or version control what you have; add a new, whole little bit to the system, and test it until it's satisfactory } until (you run out of time).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文