Monthly Archives: January 2013

The architecture of – Protocol

I’ll describe how to run a match, and how to implement a judge (and a player) if you want to add a new game to WAI.

Running a match is very simple. Each judge (an executable complied from *_judge.cpp) and players (executables complied from users’ submissions) are isolated. To run a game, just run match.exe with three parameters:

./match.exe judge player1 player2

where judge, player1, player2 are three executable file.

When match.exe starts, three processes will be forked, i.e., one judge process and two player processes. (Actually it’s six because of the sandbox, but we will ignore this for now.) There processes interact with the master process through stdin and stdout.

Let’s take the othello for example. At first, You should refer the protocol spec and sample player code here. Initially, the judge should tell one player to move firstly, and tell the other player to move secondly. He should write two messages to stdout, ”>1: first” and “>2: second”. The prefix “>x: ” indicates sending the following message to player x. (The two players are numbered 1 and 2.) So the player 1’s first scanf(“%s”, buf) will receive string “first”, while the player 2 will receive “second”. Another command for the judge is “<x“, indicating that the judge is expecting player x‘s response, and the judge’s following read from his stdin will get the string which outputted by player x. You can refer the code of othello judge.

There is another common approach for this kind of ‘interactive’ program – providing a public library interface (for example, a header file), and requiring user’s program to call the library functions for communication. However, it make user’s local debugging more difficult, because the users have to link their codes with the given library to run. And another problem is how to give out the library. We can’t just put the binary file, because the ABI may be not compatible for different C/C++ compiler, let alone for different languages in future. I believe communicating through stdin/out is simple and robust, not only for the user, but also for the platform itself.

In next post, I’ll describe the magical match.exe in detail.