Commit 865e4373 authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Add dummy bot client for LibOVCCClient API tests

parent 7961d352
/*
* 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.
*/
public class Main
{
public Main (MainLoop loop,
string nickname)
{
var player = new OVCCClient.Player (nickname);
var game = new OVCCClient.Game ();
/* when game is finished, just stop */
game.finished.connect (() => {
loop.quit ();
debug ("We're done, bye!");
});
/* we should place a tile? OK, why not */
game.place_tile.connect ((game, tile) => {
debug ("Seems we should place a tile...");
game.board.foreach ((b, p, t) => {
for (var i = 0; i < 4; i++) {
var npos = p;
switch (i) {
case 0: npos.y--; break; /* top */
case 1: npos.x++; break; /* right */
case 2: npos.y++; break; /* bottom */
case 3: npos.x--; break; /* left */
}
for (var j = 0; j < 4; j++) {
/* FIXME: this should probably be asynchronous... */
if (game.place_tile (player, npos)) {
return false;
} else {
tile.rotate (1);
}
}
}
return true;
});
});
/* we should place a pawn? let's do so */
game.place_pawn.connect ((game, tile) => {
debug ("We're asked to place a pawn!");
foreach (var o in tile.objects) {
/* we guess all pawns can go anywhere another can -- which isn't true
* using some extensions, but it doesn't matter that much. */
/* FIXME: this should probably also be asynchronous... */
if (game.place_pawn (player.pawns.nth_data (0), o)) {
break;
}
}
});
}
}
public void main (string args)
{
var l = new MainLoop ();
var m = Main (l, "A clever bot");
l.run ();
}
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