Commit d6b18368 authored by Colomban Wendling's avatar Colomban Wendling
Browse files

GTK client: test board using a live-time filling to see it happening

parent badb1c0b
......@@ -125,29 +125,47 @@ game_try_place_tile (OVCCGame *game,
return ovcc_board_foreach (board, game_do_try_place_tile, game) == FALSE;
}
struct _PlaceNextData {
OVCCGame *game;
guint n_success;
guint n_failed;
};
static gboolean
test_game (OVCCGame *game)
place_next (gpointer data)
{
OVCCTile *tile;
gsize n_success = 0;
gsize n_failed = 0;
struct _PlaceNextData *pdata = data;
OVCCTile *tile;
while (NULL != (tile = ovcc_game_get_current_tile (game))) {
if (! game_try_place_tile (game, tile)) {
g_warning ("Failed to place tile %u", ovcc_tile_get_id (tile));
n_failed ++;
} else {
n_success ++;
}
tile = ovcc_game_get_current_tile (pdata->game);
if (! tile) {
g_debug ("%u tiles over %u placed (%.3u%%)",
pdata->n_success, (pdata->n_success + pdata->n_failed),
(pdata->n_success + pdata->n_failed) > 0
? pdata->n_success * 100 / (pdata->n_success + pdata->n_failed)
: 0);
return FALSE;
}
if (! game_try_place_tile (pdata->game, tile)) {
g_warning ("Failed to place tile %u", ovcc_tile_get_id (tile));
pdata->n_failed ++;
} else {
pdata->n_success ++;
}
g_debug ("%zu tiles over %zu placed (%.3u%%)",
n_success, (n_success + n_failed),
(n_success + n_failed) > 0
? n_success * 100 / (n_success + n_failed)
: 0);
return TRUE;
}
static void
test_game (OVCCGame *game)
{
struct _PlaceNextData *pdata;
return n_failed == 0;
pdata = g_malloc (sizeof *pdata);
pdata->game = game;
pdata->n_success = 0;
pdata->n_failed = 0;
g_timeout_add_full (G_PRIORITY_DEFAULT, 100, place_next, pdata, g_free);
}
static OVCCStack *
......
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