mirror of
https://github.com/nelsbrock/dev-tictactoe.git
synced 2026-08-14 20:56:49 +02:00
fix swapped x and y coordinates
This commit is contained in:
@@ -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:
|
(ranging from 1 to 3, format `XY`) to `/dev/tictactoe` to make their first move:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
# echo 12 > /dev/tictactoe
|
# echo 22 > /dev/tictactoe
|
||||||
```
|
```
|
||||||
|
|
||||||
After player X has made their move, player O can do the same:
|
After player X has made their move, player O can do the same:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
# echo 22 > /dev/tictactoe
|
# echo 13 > /dev/tictactoe
|
||||||
```
|
```
|
||||||
|
|
||||||
To inspect the current state of the game, simply read from `/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!
|
It's X's turn!
|
||||||
|
|||||||
+2
-2
@@ -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)
|
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");
|
pr_notice("position already occupied\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
game->board[x][y] = game->next_turn;
|
game->board[y][x] = game->next_turn;
|
||||||
game->winner = tictactoe_game_check_winner(game);
|
game->winner = tictactoe_game_check_winner(game);
|
||||||
|
|
||||||
if (game->next_turn == 'X')
|
if (game->next_turn == 'X')
|
||||||
|
|||||||
Reference in New Issue
Block a user