Remote agent/Simulation/C: Difference between revisions

Content added Content deleted
m (Use {{collection}}, not {{implementation}}.)
m (formatting)
Line 1: Line 1:
{{collection|Remote agent/Simulation}}
<noinclude>{{collection|Remote agent/Simulation}}</noinclude>
Server/client programs share a lot of code, so they are all lumped together here. To compile, dump all three files in the same dir, and compile server.c and client.c separately. The server binds to port 11111. Both server and client display the current map, though only the server has the whole world, the client only knows cells the agent has been to.
Server/client programs share a lot of code, so they are all lumped together here. To compile, dump all three files in the same dir, and compile server.c and client.c separately. The server binds to port 11111. Both server and client display the current map, though only the server has the whole world, the client only knows cells the agent has been to.


server.c:
;<nowiki>server.c:</nowiki>
<lang c>#include <stdio.h>
<lang c>#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
Line 133: Line 133:
}</lang>
}</lang>


client.c:
;<nowiki>client.c:</nowiki>
<lang c>#include <stdio.h>
<lang c>#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
Line 407: Line 407:
}</lang>
}</lang>


and share source "common.c":
;<nowiki>common.c:</nowiki>
<lang c>struct agent_t{ int x, y, facing, ball; } agent = { 0, 0, 0, -1 };
<lang c>struct agent_t{ int x, y, facing, ball; } agent = { 0, 0, 0, -1 };
enum {
enum {