mirror of
https://github.com/nelsbrock/dev-tictactoe.git
synced 2026-08-14 20:56:49 +02:00
Compare commits
2
Commits
4520ba5b61
...
ebaf64982d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebaf64982d
|
||
|
|
ac4d4eb4fa
|
+4
-3
@@ -21,13 +21,14 @@ int tictactoe_game_init(ttt_game_t *game)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Steps over the board, starting from position (start_x, start_y) and ending
|
* Steps over the board, starting at position (start_x, start_y) and ending
|
||||||
* at the board's boundaries, checking if all cells are occupied by the same
|
* at the board's boundaries, checking if all cells are occupied by the same
|
||||||
* player.
|
* player.
|
||||||
*
|
*
|
||||||
* start_x and start_y must lie within the board's boundaries.
|
* start_x and start_y must be within the board's boundaries.
|
||||||
*
|
*
|
||||||
* Returns the respective player, or '\x00' if a cell isn't occupied.
|
* Returns the respective player, or '\x00' if no single player occupies all
|
||||||
|
* cells within the specified streak.
|
||||||
*/
|
*/
|
||||||
static char tictactoe_game_check_streak(ttt_game_t *game, size_t start_x,
|
static char tictactoe_game_check_streak(ttt_game_t *game, size_t start_x,
|
||||||
size_t start_y, ssize_t step_x,
|
size_t start_y, ssize_t step_x,
|
||||||
|
|||||||
+4
-5
@@ -94,7 +94,7 @@ static ssize_t tictactoe_write(struct file *file, const char __user *buf,
|
|||||||
{
|
{
|
||||||
char *command_buf;
|
char *command_buf;
|
||||||
size_t count_without_lf;
|
size_t count_without_lf;
|
||||||
size_t human_x, human_y;
|
size_t x, y;
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -145,8 +145,8 @@ static ssize_t tictactoe_write(struct file *file, const char __user *buf,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
human_x = (size_t)(command_buf[0] - '0');
|
x = (size_t)(command_buf[0] - '1');
|
||||||
human_y = (size_t)(command_buf[1] - '0');
|
y = (size_t)(command_buf[1] - '1');
|
||||||
|
|
||||||
kfree(command_buf);
|
kfree(command_buf);
|
||||||
|
|
||||||
@@ -163,8 +163,7 @@ static ssize_t tictactoe_write(struct file *file, const char __user *buf,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tictactoe_game_make_turn(tictactoe_current_game, human_x - 1,
|
if (tictactoe_game_make_turn(tictactoe_current_game, x, y)) {
|
||||||
human_y - 1)) {
|
|
||||||
mutex_unlock(&tictactoe_mutex_current_game);
|
mutex_unlock(&tictactoe_mutex_current_game);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user