From 741e08ab9d605852baa502fd6eccf39bc0d0015d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Crist=C3=B3v=C3=A3o=20Cruz?= Date: Tue, 6 Apr 2010 12:38:15 +0100 Subject: [PATCH] Clear screen in the end. --- funnysort.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/funnysort.c b/funnysort.c index 8e827ad..6f24f76 100644 --- a/funnysort.c +++ b/funnysort.c @@ -58,6 +58,7 @@ void erase_board (board_t *board) { conglReset(); conglClearScreen(); + conglMoveCursor(1, 1); } void move_sorter(board_t *board, sorter_t *sorter) @@ -93,25 +94,23 @@ void move_sorter(board_t *board, sorter_t *sorter) } while ((item != EMPTY) && (ncycles < SORTER_MOVE_TRIES)); /* If sorter failed to move, respawn in random position */ - if (item != EMPTY) { - do { - newline = random()%HEIGHT; - newcolumn = random()%WIDTH; + while (item != EMPTY) { + newline = random()%HEIGHT; + newcolumn = random()%WIDTH; - /* lock position to where the sorter may move */ - pthread_mutex_lock((board->lock)[newline]+newcolumn); - peek_item(newline, newcolumn, board, &item); - if (item != EMPTY) { - /* unlock if position if not available */ - pthread_mutex_unlock((board->lock)[newline]+newcolumn); - } - } while (item != EMPTY); + /* lock position to where the sorter may move */ + pthread_mutex_lock((board->lock)[newline]+newcolumn); + peek_item(newline, newcolumn, board, &item); + if (item != EMPTY) { + /* unlock if position if not available */ + pthread_mutex_unlock((board->lock)[newline]+newcolumn); + } } /* Update board. */ /* Don't reset the item if sorter just droped one. */ - /* If an item was droped, it will be different of SORTER. */ + /* If an item was droped, it will be different from SORTER. */ peek_item(sorter->line, sorter->column, board, &sorter_item); if (sorter_item == SORTER) { poke_item (sorter->line, sorter->column, board, EMPTY); -- 2.11.4.GIT