From: Carl Worth Date: Thu, 15 Dec 2005 05:48:11 +0000 (+0000) Subject: 2005-12-14 Carl Worth X-Git-Url: https://git.cworth.org/git?p=ttt;a=commitdiff_plain;h=8c8f61b622b928b3a670ceaeea426321e72378d4 2005-12-14 Carl Worth * src/ttt-server.h: Update the documentation of these functions to be more precise about what happens to client mutexes. * src/ttt-board.c: (ttt_board_is_won): And some white space to make things more readable. --- diff --git a/ChangeLog b/ChangeLog index 7162d37..e909c67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-12-14 Carl Worth + + * src/ttt-server.h: Update the documentation of these functions to + be more precise about what happens to client mutexes. + + * src/ttt-board.c: (ttt_board_is_won): + 2005-12-13 Bryan Worth * src/ttt-curses-client: Cleaned up text-entry code. Added support for HOME, END, DELETE, and ARROW keys diff --git a/src/ttt-board.c b/src/ttt-board.c index 73d2741..f8f62e0 100644 --- a/src/ttt-board.c +++ b/src/ttt-board.c @@ -121,16 +121,40 @@ ttt_error_t ttt_board_make_move (ttt_board_t *board, int move) ttt_cell_t ttt_board_is_won (ttt_board_t *board) { int i; + + /* Loop over rows and columns looking for a win. */ for (i = 0; i <= 2; i++) { - if (board->cells[i] != TTT_CELL_EMPTY && board->cells[i] == board->cells[i + 3] && board->cells[i] == board->cells[i + 6]) - return(board->cells[i]); - else if (board->cells[i * 3] != TTT_CELL_EMPTY && board->cells[i * 3] == board->cells[(i * 3) + 1] && board->cells[i * 3] == board->cells[(i * 3) + 2]) - return(board->cells[i * 3]); + /* Check the current column */ + if (board->cells[i] != TTT_CELL_EMPTY && + board->cells[i] == board->cells[i + 3] && + board->cells[i] == board->cells[i + 6]) + { + return board->cells[i]; + } + + /* Check the current row */ + if (board->cells[i * 3] != TTT_CELL_EMPTY && + board->cells[i * 3] == board->cells[(i * 3) + 1] && + board->cells[i * 3] == board->cells[(i * 3) + 2]) + { + return board->cells[i * 3]; + } + } + + if (board->cells[0] != TTT_CELL_EMPTY && + board->cells[0] == board->cells[4] && + board->cells[0]== board->cells[8]) + { + return board->cells[0]; } - if (board->cells[0] != TTT_CELL_EMPTY && board->cells[0] == board->cells[4] && board->cells[0]== board->cells[8]) - return(board->cells[0]); - if (board->cells[2] != TTT_CELL_EMPTY && board->cells[2] == board->cells[4] && board->cells[2]== board->cells[6]) - return(board->cells[2]); - return(TTT_CELL_EMPTY); + + if (board->cells[2] != TTT_CELL_EMPTY && + board->cells[2] == board->cells[4] && + board->cells[2]== board->cells[6]) + { + return board->cells[2]; + } + + return TTT_CELL_EMPTY; } diff --git a/src/ttt-server.h b/src/ttt-server.h index 80f22bf..5575d10 100644 --- a/src/ttt-server.h +++ b/src/ttt-server.h @@ -50,8 +50,8 @@ ttt_server_unregister_client (ttt_server_t *server, ttt_client_t *client); /* Send a message to all connected clients. * * Locking: The server mutex will be acquired and held throughout the - * execution of this function. Each client mutex may also be acquired - * and held by functions called during the execution of this function. + * execution of this function. Each client mutex will also be acquired + * for a portion of the execution of this function. * * Errors: If an error such as an IO error occurs, this function will * not return. @@ -64,8 +64,7 @@ ttt_server_broadcast (ttt_server_t *server, const char *message); * function and will need to be free'd by the caller. * * Locking: The server mutex will be acquired and held throughout the - * execution of this function. Each client mutex may also be acquired - * and held by functions called during the execution of this function. + * execution of this function. * * Errors: If an error such as an IO error occurs, this function will * not return. @@ -92,8 +91,7 @@ ttt_server_verify_username (ttt_server_t *server, * found. * * Locking: The server mutex will be acquired and held throughout the - * execution of this function. Each client mutex may also be acquired - * and held by functions called during the execution of this function. + * execution of this function. * * Errors: If an error such as an IO error occurs, this function will * not return. @@ -106,8 +104,7 @@ ttt_server_get_client_from_username (ttt_server_t *server, /* Adds an invitation * * Locking: The server mutex will be acquired and held throughout the - * execution of this function. Each client mutex may also be acquired - * and held by functions called during the execution of this function. + * execution of this function. * * Errors: If an error such as an IO error occurs, this function will * not return. @@ -123,8 +120,7 @@ ttt_server_add_invite (ttt_server_t *server, * found. * * Locking: The server mutex will be acquired and held throughout the - * execution of this function. Each client mutex may also be acquired - * and held by functions called during the execution of this function. + * execution of this function. * * Errors: If an error such as an IO error occurs, this function will * not return.