Remote agent/Simulation/C: Difference between revisions

no edit summary
(bug fix)
imported>Katsumi
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 3:
 
;<nowiki>server.c:</nowiki>
<syntaxhighlight lang="c" line>
<lang c>#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Line 131 ⟶ 132:
 
return 1;
}</langsyntaxhighlight>
 
;<nowiki>client.c:</nowiki>
<syntaxhighlight lang="c" line>
<lang c>#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Line 406 ⟶ 408:
turn(c_cw), say(c_cw), hear();
try_forward(fd);
}
}</lang>
</syntaxhighlight>
 
;<nowiki>common.c:</nowiki>
<syntaxhighlight lang="c" line>
<lang c>struct agent_t{ int x, y, facing, ball; } agent = { 0, 0, 0, -1 };
enum {
c_fwd, c_cw, c_ccw, c_get, c_drop, c_over, c_stop,
Line 420 ⟶ 424:
};
 
const char *cmds = "^><@!+.RGYBrgyb|SAsa";
inline int cmd_to_char(int c) { return cmds[c]; }
inline int char_to_cmd(int c) {
Line 551 ⟶ 555:
}
 
const char *colors[] = { "31", "32", "33", "34" };
const char *ag[] = { "<V>A" };
 
inline int cell_color(byte **f, int x, int y)
Line 612 ⟶ 616:
if (dir == c_cw)
if (++agent.facing > 3) agent.facing = 0;
}
}</lang>
</syntaxhighlight>
Anonymous user