From ac4d4eb4fa8e3b9397d4303e8e507fd21365dcda Mon Sep 17 00:00:00 2001 From: Niklas Elsbrock Date: Thu, 20 Mar 2025 20:35:03 +0100 Subject: [PATCH] simplify parsing of coordinates --- tictactoe_main.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tictactoe_main.c b/tictactoe_main.c index 659da04..730f96d 100644 --- a/tictactoe_main.c +++ b/tictactoe_main.c @@ -94,7 +94,7 @@ static ssize_t tictactoe_write(struct file *file, const char __user *buf, { char *command_buf; size_t count_without_lf; - size_t human_x, human_y; + size_t x, y; if (count == 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'); - human_y = (size_t)(command_buf[1] - '0'); + x = (size_t)(command_buf[0] - '1'); + y = (size_t)(command_buf[1] - '1'); kfree(command_buf); @@ -163,8 +163,7 @@ static ssize_t tictactoe_write(struct file *file, const char __user *buf, #endif } - if (tictactoe_game_make_turn(tictactoe_current_game, human_x - 1, - human_y - 1)) { + if (tictactoe_game_make_turn(tictactoe_current_game, x, y)) { mutex_unlock(&tictactoe_mutex_current_game); return -EINVAL; }