Overview

Your worm brain is an executable program. If it was called ./foo for example, you would call the simulator like this: ./p3game i1a ./foo

The simulator spawns the ./foo process for you. Your program should read from standard in to receive messages from the simulator, write to standard out to send messages to the server, and write to standard error whenever you have debugging messages you want to show up in the terminal. Messages always consist of a single line, terminated by a newline character. Each message you read from the simulator will start with a single character that tells you what kind of message you're dealing with.

PROLOGUE MESSAGES - I.e. prior to the game starting
message formatexampledescription
g rows cols dur len g 20 20 120 9 First message of the game. Tells you you've got a rows x cols board, the time limit is dir steps, and worms have length len.
r row col len r 4 2 8 Tells you there is a barrier of len cells, which extends to the right from position row,col.
d row col len d 2 15 11 Tells you there is a barrier of len cells, which extends to down from position row,col.
o row col o 2 15 Tells you there is a food object at location row,col. Note there are never multiple pieces of food at the same location.
s row col dir s 10 10 N Tells you the that the game is starting, and you are at position row,col pointing in direction N. This message ends the "prologue".

After the prologue messages you go into a communication loop in which you go through this cycle:

 .--> [ receive: extra-messages ]* ---> receive: move-request ---> send: your-move-response ---> receive: ack -------------.
 |               w or x                             m                     R,L,F,B                          k               |
 |                                                                                                                         |
 |      ignore these messages if       example: "m 10" means it's    respond with a single      the-response-code-tells    |
 |      there is only one worm         round 10, make a move!        letter: remember '\n'      you-if-the-move-succeeded  |
 \_________________________________________________________________________________________________________________________/
											 
GAME PLAY MESSAGES - I.e. as the game progresses
message formatexampledescription
w row col id w 3 7 2 Tells you the location at the start of the current round of the heads of the other worms in the game. You get one for each "other" worm. If there are no other worms, you don't get any of these. Note: Each worm has an "id" which is an integer 0,1,2,3.
x row col x 3 7 tells you that the food at location row,col was eaten in the previous round.
m roundnum m 16 requests your move for round roundnum.
You must respond to this message with L = turn-left-and-step, R = turn-right-and-step, F = step-forward, B = turn-180-and-step. You may also use N,S,E,W if you like. Don't forget a newline at the end!
k code k 0 acknowledges your move. The code is one of: 0 = move OK, 1 = move OK and you ate a piece of food, 2 = move failed. When your move fails, the "turn" part of the move succeeds, so you are facing the right direction, it's just that the forward step part of the move failed either because you ran into a barrier, a board boundary, or another worm.