Commit 5ec3714c authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Bot: little code cleanup

parent 926953d6
/*
* A sample bot.
* Currently it is dummy code only to develop the API. It doesn't compile and
* it probably don't use the better API ever. Let's see.
*/
/* maybe inherit from Client? */
public class Bot
{
private MainLoop loop = null;
......@@ -13,7 +12,7 @@ public class Bot
public bool join (OVCCClient.Server server)
throws Error
{
uint player_suffix = 7;
uint player_suffix = 7;
client = new OVCCClient.Client ();
......@@ -22,7 +21,7 @@ public class Bot
/* login to the server, choosing an available nickname */
debug ("Trying to login...");
do {
while (true) {
try {
client.login ("""Clever bot %03u""".printf (player_suffix));
break;
......@@ -36,7 +35,6 @@ public class Bot
throw e;
}
}
while (true);
debug ("Logged in with player_suffix = %u", player_suffix);
/* join any open table */
......@@ -54,14 +52,13 @@ public class Bot
/* react on game state changes */
client.game.notify["state"].connect ((s, p) => {
switch (((OVCC.Game)s).state)
{
switch (((OVCC.Game)s).state) {
case OVCC.GameState.FINISHED:
loop.quit ();
leave ();
debug ("We're done, bye!");
break;
case OVCC.GameState.ABORTED:
loop.quit ();
leave ();
debug ("Abnormal game termination!");
break;
}
......@@ -147,12 +144,10 @@ private static void setup_signal_handlers ()
#endif
Bot bot = null;
Bot bot = null;
public int main (string[] args)
{
MainLoop loop = null;
OVCCClient.Server server = null;
var host = "localhost";
uint16 port = 0xdead;
......@@ -163,9 +158,9 @@ public int main (string[] args)
port = (uint16)int.parse (args[2]);
}
loop = new MainLoop ();
var loop = new MainLoop ();
var server = new OVCCClient.Server (host, port);
bot = new Bot (loop);
server = new OVCCClient.Server (host, port);
#if HAVE_POSIX
setup_signal_handlers ();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment