Implementing AI wars where code is the primary asset. (focus on Terrarium)

The one thing I've taken away from the .NET Terrarium in terms of AI development is that players value their code over everything else. Protecting code from being viewed by other users is extremely difficult and hard to implement. After all, the focus of a distributed AI game is to pass the intelligence all over the place, to multiple machines, so it can operate across a large number of machines and potentially become the dominant system. If the code leaves your machine, it becomes possible that other users are going to steal your code, plain and simple. You can try trusting some other environments, perhaps a central server that hosts your code, but even then your code exists somewhere that you aren't in charge of basic protection.

Code as an Asset:
The development of new AI in the Terrarium was driven by the decompilation and examination of existing code. To show you how pervasive code dissassembly was, we introduced an Animal Farm, or location where users could share code. Even with this central repository of code, we constantly saw users working in ILDasm and ILAsm to produce verbatim copies of existing AI. The existing code as considered an asset by not only the developer, but also by the rest of the players. Controlling that asset meant possibly controlling the Terrarium's game world. Code is such an asset that users will go to any length to get their hands on it.

What is the best way to protect your assets? Well, don't create a situation where your assets fall into the hands of other users. Why do you think ASP .NET is so popular and Windows Forms is still riding coat tails? People can protect their code assets when it comes to server side coding, but find it much harder to protect code on the client. This is a common problem. So if you want code protection, you need to host your assembly either at a central server level or from your own machine. If you follow these guidelines then users will be more likely to participate and generate professional level AI while still protecting their investment in programming the code.

Execution Time as an Asset:
We've identified three places to run the AI. You can operate at the local client level, at the server level, or at a distributed client level. Identifying execution time as an asset, load balancing across the greater distributed network of all clients is going to yield the best results in terms of execution time. The resources are apparently limitless as long as you can maintain a large user base. In reality, users aren't always connected. The only 100% up-time resource is going to be your server. You can run AI on the server, but then you run the risk of not having enough execution time to schedule the AI as the game becomes more and more popular. You can offload this risk by allowing users to host their own personal servers and implementing relatively simple queueing routines.

The most limited location to run the AI is on the local client. Each user that produces AI hosts a networkable interface through which their AI can operate. This is the most resource consumptive option because it entails replicating a large amount of game state down to the local client and the propagation of AI commands back up to wherever the game is being hosted. Your AI is bound by the amount of processor time you want to give it. Further, you can only host a single instance of your AI at a time (potentially more in a more robust hosting environment).

Up-Time as an Asset:
Looking at our three models again, the natural next step is examining up-time. If you are programming an AI it is truly an investment of time and effort, but should it also be an investment of your own computer time? In the distributed model it up-time becomes a non-issue as long as the server is available to server AI assemblies down to distributed clients that do all of the processing. The server model is fairly identical in that your AI is playable as long as the server is up and people are selecting it as an opponent. The problem with local client interfaces is that your AI is only around as long as you are. You have to maintain an interface for people to connect through.

Can we solve the up-time problem for local only hosting? Yes, if we trust someone else to host our code for us. This is a sticky point, but we can share a hosting location with a number of friends, family, colleagues where we each host an AI off of the same box. This box might be a web server or similar online resource, and once the AI is loaded, it now acts as an AI interface in addition to it's other roles. A third option is the pay for play option where you AI is hosted by the game originator for a small maintenance fee proportional to keeping their server up and running with your AI on it.

Penalties:
This is really important and something a lot of people don't think about. How many different ways can code hose a machine? Plenty right? You can get stuck in an infinite loop and never return, you can run a machine out of memory, you can screw up a static initializer, you write finalizers in your code to hang the GC. Who should be penalized for bad code? If you allow AI to run on the server or distributed clients then everyone is going to pay the price for bad code. Forcing code to run at the local client level means only the original AI developer is going to pay the penalty for bad code.

Can you get around all of those issues in server or distributed hosting? Sure, but I offer the following advice. Fixing the hosting problems comes in the form of adding constraints. These constraints are based on usage scenarios and known patterns of attack. They leverage existing code protection features as much as possible. In the end, you have a system capable of doing nearly all of the things the original system could do, minus a select few things that are considered unsafe. From the other end of the spectrum, you can explicitly enable features one by one. This direction is safer, but much more limited. It is akin to a custom scripting language because you have full control over what the underlying code is capable of. .NET doesn't currently offer good facilities to make this a possibility. You can't explicitly enable access to only certain classes, and disable all other access. You can't hook into the memory management functionality and suppress creation of objects once the component has reached it's limits. They may be available as Whidbey roles around in the form of hosting protections, but that will be a code-path much more difficult to code than the average .NET programmer will be able to handle.

At the end of the day the penalties should probably be placed right back on the AI developer. In a real game, AI developers are just as responsible for bugs as the rest of the development team. In fact, if there is a bug in the AI, it often takes down the entire game. In a developer game the model is switched because the AI now becomes an unknown and the AI developer may not bear the brunt of poorly written code. In fact, there are issues with developer code in the Terrarium that only manifest after the code has traversed several machines and is widely available when an odd code-path is run through.

I'm leaning more and more towards a local client hosting model for developer based AI games for a number of reasons. I think I've mentioned the potential network models that allow AI and Networked players to operate almost transparently by taking advantage of a network protocol. Now stack the asset protection on top of that along with the ability to remove advanced code hosting features and you have yourself a definite winner.

Published Tuesday, September 28, 2004 4:44 AM by Justin Rogers

Comments

Tuesday, September 28, 2004 11:02 AM by Mike Swaim

# Winforms vs ASP.Net

I think that ASP.Net is so popular because it's much better old ASP. WinForms hasn't caught on for a variety of reasons. There's the large deployment package (.net), the pain of conversion of old VB code, the slow start up speed vs. native code. It's often slower than native code, and the UI's particularly slower than native code. And from a Delphi perspective, you have fewer controls that aren't as useful.
Plus, you've got Avalon coming along in a couple of years that'll obsolete WinForms anyway. Why jump to a temporary solution?
Tuesday, September 28, 2004 12:12 PM by Gabe Halsmer

# Oh really...


Interesting take on code security. However, you're describing a very unique situation. Terrarium is a game played by people with more time then I have. Defeating a dominant animal requires understanding its behavior. Either through watching it, experimentation, or as some people have opted for, reverse engineering its code.


:: Why do you think ASP .NET is so
:: popular and Windows Forms is still
:: riding coat tails?

Ease of deployment. Seriously, you don't think code protection is why people choose ASP.NET. How many window form apps do you think are reverse engineered?

Tuesday, September 28, 2004 3:17 PM by Justin Rogers

# re: Implementing AI wars where code is the primary asset. (focus on Terrarium)

Professional component developers have their number 1 gripe at code being too easy to disassemble. They feel their intellectual property is constantly being examined and taken away from them. In a server environment, they feel that have slighly more control, especially if they own the site. In a Windows Forms application, you own nothing once it is on the end users machine. I happen to know for a fact, that many developers, including many large game houses have chosen not to use C# because of their perception that code is an asset and placing it on the end users machine is much riskier they feel than their current development platforms.

The concept that Windows Forms will be obsolete in a couple of years is stretching it, especially considering the Windows Forms/Avalon interop. Windows Forms will be around for quite some time, probably another 5 years. After 5 years it will succumb to future technologies, just like every other technology that hits the market, the lifetime is limited by some future advancement. People program DirectX every single day, and every 2 years it gets obsoleted for a brand new version.
Tuesday, September 28, 2004 3:36 PM by Justin Rogers

# re: Implementing AI wars where code is the primary asset. (focus on Terrarium)

Code Security Note: What is the first thing people did when ATI came out with their control panel? I think I saw quite a few blogs with the IL and people ripping off their controls. I chose the route of visually examining their controls and making something similar, but most people just wripped the IL.

AI: I also need to point out that many people that put time in the Terrarium are also professional developers by day, hobbyists at times, and students. While you might feel they have more *time* than you, Terrarium is a game and a competition. Understanding their explicit behavior rather than programming a resilient creature is a break in the paradigm and circumvents all competition. I really wish we had fixed that.

Question: If there were an IntellectualProperty attribute you could place on an assembly, that upon opening in ILDasm or Reflector, you'd get a message telling you the source was intellectually protected. Would you do the right thing and have the app close down without actually looking at the code? This is a social engineering approach to prevent arbitrary glancing at code you know someone cares about.

Leave a Comment

(required) 
(required) 
(optional)
(required)