The game is a multiplayer simple real time strategy housed in a Flash application. Players run the Flash client, and are connected to a server written in another language (the language is irrelevant). Players compete against one another in games of 2~8 players.

My aim is create some way for people to create an AI agent to play in the same realm against human players, or other AI agents. Akin to the Broodwar AI competitions, but in a much simpler game.

The current model

has players logging in to the lobby. Games seeking players are listed in the lobby. Once the game acquires the amount of players required to start (defined by the host at game room creation time), the players are then pushed into a game, and leave the lobby. Games then run through to completion; players who disconnect are left stagnant until destroyed or they login again and are reconnected to the game.

In a perfect world

the flash client (Using an MVC type model) would be able to interface in some way with the users AI agent, handing data to the agent, and receiving commands from the agent. In this way the user could observe the game in the flash client while in play, as well as choose games for the agent to participate in. This model would be ideal for debugging purposes, as to not interrupt play on crash, and since commands can only be sent (with malformed commands being ignored, with an error callback) users could pick out major bugs quickly.


flash is a prissy little nitwit when it comes to communicating client side to client side. The only realistic options I can see would be to create a second client interface in another language (say .Net) that would be used to interface the AI agent, the player would then login to the flash client and enter games/observe in the above mentioned manner. OR the flash client would create a second socket pointed at the local host. A suitable API would be created to manage the communication protocol (as a DLL or similair) that would handle all data values of the game, and sending commands. This API would be extended by the users AI agent, and the player would login to the flash client and join/observe games.

The Big Question:

From experience or observations, what would be the most suitable model for this type of a system? I have no qualms with either, but due to the long timeframe of implementing each system (I work alone) I'd rather start off on the right path, and end up with an easy to use model. Any suggestions at all are very welcome!

  • 2
    \$\begingroup\$ You lost me with the "client side to client side" communication. Do you want to implement the A.I. in a separate flash file (swf) and then have that communicating with your existing game? Why do you want to implement the A.I. client-side anyways? \$\endgroup\$
    – bummzack
    Aug 24, 2011 at 15:45
  • \$\begingroup\$ I'm with you bummzack. @OP: Perhaps some detail on what this communication method you mention is (P2P sockets?) and what makes it so hard to achieve -- a lack of good socket support in Flash? Or what? Then furthermore you ask what "model" you should use -- model of what? The client-side application architecture, i.e. MVC, the networking architecture, or both, or everything (including server-side architecture)? \$\endgroup\$
    – Engineer
    Aug 24, 2011 at 16:00
  • 1
    \$\begingroup\$ Client to Client in the sense that one process may latch to another, possibly better named Client to Self. I'm seeking a model to allow players to create an AI that will play the game, the AI is hosted on their machine, but plays like a player would THROUGH the client, which connects to a server where the game is hosted. See this link: code.google.com/p/bwapi for a sense of what I'm trying to achieve with my own game. \$\endgroup\$ Aug 24, 2011 at 16:12
  • 2
    \$\begingroup\$ So it's to create some kind of AI championship? If so, I wouldn't be using the Flash client at all. I see two options: simply document the protocol currently used between the Flash client and the server, so AI developers could implement this protocol in the language of their choice and connect to the server directly. Or create a library (an SWC if you want to stick to Flash) that provides an API to connect and interact with the remote server, so your AI developers could use this library to base their AI on. \$\endgroup\$
    – Tyn
    Aug 24, 2011 at 16:20
  • 2
    \$\begingroup\$ @Tyn: Good point about the SWC file. Why not make that an answer? \$\endgroup\$
    – bummzack
    Aug 24, 2011 at 18:27

2 Answers 2


So your goal is to provide an interface for developers to plug their AI on your game system. Depending on how much freedom you want to provide to those developers, you have several options.

  1. For the largest freedom, do not provide anything but a comprehensive documentation of your network protocol as well as a set of IP to connect to (and maybe a test server).

    Using that approach, third-party developers are free to develop an AI in any language they are the most comfortable with, as soon as it supports sockets. On the downside, your server have to be quite secure and stable to avoid cheating and attacks. But that should be the case anyway.

  2. For almost as much freedom, provides a library that allows to connect and interact with your game server. If you want to stick to Flash, you can give the developers an SWC. This way, they could create their own Flash app, that connects and interact with your game server using your library.

    This is maybe more flexible, since you can update the library when changing your network protocol, without breaking the third-party applications (or at least, with giving them a quite easy way to update, compared to a random change in the protocol).

  3. You could also set up your game client so it will be able to read client-side scripts. For example, you could use LUA. This way, you are really sandboxing the third-party code on your very own game client, and you keep all control over the API you'll be providing.

If you'd like to specify your request more deeply, I'd be happy to update the answer with more details.

  • \$\begingroup\$ I've written an interpreted AI language (through AS3) in the past, but never thought about using LUA, could you briefly describe how LUA might be utilized in this instance, and perhaps what kind of performance bottlenecks I may be looking at by housing it in Flash? \$\endgroup\$ Aug 25, 2011 at 13:10

You could probably use flash.net.LocalConnection for this. This would allow you to implement an API where other flash files can connect to and run commands locally.

What this means is, that you'll have your game client (running in the browser) which exposes methods through LocalConnection. Somebody that implements an A.I. for your client could either run an Adobe AIR application, or another SWF file in the browser that connects to your LocalConnection and issues commands over it.

This could get cumbersome with lots of exposed methods and requires really good documentation, so that somebody can work with your API.

Another option would be to expose a RESTful web API, that any client can connect to. So the A.I. could be implemented in any language that can issue an HTTP-request.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .