Compare commits

...
2 Commits
Author SHA1 Message Date
nelsbrock 610bc1c07c fix swapped x and y coordinates 2026-04-04 21:34:13 +02:00
nelsbrock 12eba69eb1 fix: increase *ppos in tictactoe_write 2026-04-04 21:12:41 +02:00
3 changed files with 10 additions and 6 deletions
+4 -4
View File
@@ -22,13 +22,13 @@ After loading the module, player X can write grid coordinates
(ranging from 1 to 3, format `XY`) to `/dev/tictactoe` to make their first move:
```console
# echo 12 > /dev/tictactoe
# echo 22 > /dev/tictactoe
```
After player X has made their move, player O can do the same:
```console
# echo 22 > /dev/tictactoe
# echo 13 > /dev/tictactoe
```
To inspect the current state of the game, simply read from `/dev/tictactoe`:
@@ -39,9 +39,9 @@ To inspect the current state of the game, simply read from `/dev/tictactoe`:
```
#####
# X #
# O #
# #
# X #
#O #
#####
It's X's turn!
+2 -2
View File
@@ -111,12 +111,12 @@ static char tictactoe_game_check_winner(ttt_game_t *game)
*/
int tictactoe_game_make_turn(ttt_game_t *game, size_t x, size_t y)
{
if (game->board[x][y] != ' ') {
if (game->board[y][x] != ' ') {
pr_notice("position already occupied\n");
return -1;
}
game->board[x][y] = game->next_turn;
game->board[y][x] = game->next_turn;
game->winner = tictactoe_game_check_winner(game);
if (game->next_turn == 'X')
+4
View File
@@ -128,6 +128,8 @@ static ssize_t tictactoe_write(struct file *file, const char __user *buf,
tictactoe_game_init(tictactoe_current_game);
mutex_unlock(&tictactoe_mutex_current_game);
kfree(command_buf);
*ppos += count;
return count;
}
@@ -169,6 +171,8 @@ static ssize_t tictactoe_write(struct file *file, const char __user *buf,
}
mutex_unlock(&tictactoe_mutex_current_game);
*ppos += count;
return count;
}