+2005-12-14 Carl Worth <cworth@cworth.org>
+
+ * 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 <bryan@theworths.org>
* src/ttt-curses-client: Cleaned up text-entry code. Added support
for HOME, END, DELETE, and ARROW keys
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;
}
/* 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.
* 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.
* 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.
/* 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.
* 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.