\$\begingroup\$

Wrapper for Non-Java Submissions

NOTE MAP_SIZE support has been added. If you care, please update your submission accordingly.

This is community wiki entry for a wrapper, usable by those who want to play but don't like/don't know Java. Please use it, have fun, and I'm happy to help you get things set up.

It's pretty late here as I'm finishing up, so other Java coders, please look this over and suggest improvements. If you can, do so via my github repository by filing an issue or submitting a patch. Thanks!

This entire is being distributed with the UNLICENSE, please follow/fork it from its github repository. Submit patches there if you find issues and I'll update this post.

Current Examples of Wrapper in Use

plannapus: WolfCollectiveMemory in R

user3188175: SmartWolf in C#

toothbrush: Toothbrush in ECMAScript

How to use

What follows are instructions on the protocol for-inter process communication via PIPES I have defined for remote Wolves. Note I've skipped MAP_SIZE as this doesn't appear to exist, in spite of its presence in OP's problem statement. If it does appear, I'll update this post.

IMPORTANT NOTES:

Only a single invocation of your external process will be made (so wrap your processing logic in an infinite loop. This also lets you keep any processing in-memory, instead of using disk)

All communication is to this single external process via STDIN and STDOUT

You must explicitly flush all output sent to STDOUT, and make sure it is newline-terminated

Specification

Remote scripts are supported by a simple protocol via STDIN and STDOUT hooks, and is split into initialization, Move, and Attack. In each case communication with your process will be via STDIN, and a reply is necessary from STDOUT. If a reply is not received in 1 second, your process will be assumed to be dead and an exception will be thrown. All characters will be encoded in UTF-8, for consistency. Every input will terminate with a newline character, and your process should terminate every output reply with a newline as well. WARNING Be sure to flush your output buffer after every write, to ensure the Java wrapper sees your output. Failure to flush may cause your remote Wolf to fail.

Note that only a single process will be created, all Wolves must be managed within that one process. Read on for how this spec will help.

Initialization

STDIN: S<id><mapsize>



STDOUT: K<id>



<id> : 00 or 01 or ... or 99

Explanation:

The character S will be sent followed by two numeric characters 00 , 01 , ..., 99 indicating which of the 100 wolves is being initialized. In all future communication with that specific wolf, the same <id> will be used.

Following the ID, a variable length sequence of numeric characters will be be sent. This is the size of the map. You'll know the sequence of numeric characters is over when you reach the newline (

).

To ensure your process is alive, you must reply with the character K followed by the same <id> you received. Any other reply will result in an exception, killing your wolves.

Movement

STDIN: M<id><C0><C1>...<C7><C8>



STDOUT: <mv><id>



<Cn> : W or or B or S or L

W : Wolf

: Empty Space

B : Bear

S : Stone

L : Lion

<mv> : H or U or L or R or D

H : Move.HOLD

U : Move.UP

L : Move.LEFT

R : Move.RIGHT

D : Move.DOWN

Explanation:

The character M will be sent followed by the two character <id> to indicate which Wolf needs to choose a move. Following that, 9 characters will be sent representing that Wolf's surroundings, in row order (top row, middle row, bottom row from leftmost to rightmost).

Reply with one of the valid movement characters <mv> , followed by the Wolf's two digit <id> for confirmation.

Attack

STDIN: A<id><C>



STDOUT: <atk><id>



<C> : W or B or S or L

<atk> : R or P or S or D

R : Attack.ROCK

P : Attack.PAPER

S : Attack.SCISSORS

D : Attack.SUICIDE

Explanation:

The character A will be sent followed by the two character <id> to indicate which Wolf is participating in an attack. This is followed by a single character <C> indicating which type of thing is attacking, either a W olf, B ear, S tone, or L ion.

Reply with one of the <atk> characters listed above, indicating what your response to the attack is, following by the two digit <id> for confirmation.

And that's it. There's no more to it. If you lose an attack, that <id> will never be sent to your process again, that's how you will know your Wolf has died -- if a complete Movement round has passed without that <id> ever being sent.

Conclusion

Note that any exceptions will kill all the Wolves of your remote type, as only a single "Process" is constructed of your remote wolf, for all wolves of your type that get created.

In this repository you'll find the Wolf.java file. Search and replace the following strings to set up your bot:

Replace <invocation> with the command line argument that will properly execute your process.

Replace <custom-name> with a unique name for your Wolf.

For an example look at the repository, where I have WolfRandomPython.java that invokes my example remote, the PythonWolf.py (a Python 3+ Wolf).

Rename the file to be Wolf<custom-name>.java , where <custom-name> is replaced with the name you chose above.

To test your Wolf, compile the Java program ( javac Wolf<custom-name>.java ), and follow Rusher's instructions to include it in the simulation program.

Important: Be sure to provide clear, concise instructions on how to compile/execute your actual Wolf, which follows the scheme I've outlined above.

Good luck, and may nature be ever in your favor.

The Wrapper Code

Remember, you MUST do the searches and replaces outlined about for this to work. If your invocation is particularly hairy, please contact me for assistance.

Note there is a main method in this wrapper, to allow rudimentary "pass/fail" testing on your local box. To do so, download the Animal.java class from the project, and remove the package animals; line from both files. Replace the MAP_SIZE line in Animal.java with some constant (like 100). Compile them using javac Wolf<custom-name>.java an execute via java Wolf<custom-name> .