From c1a044640226a4f51bd759de19b76fda2c09b7bc Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Fri, 8 Oct 2021 16:39:57 +0200 Subject: [PATCH] Add a test for i in set_tictactoe_winner() --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 1 - src/model.c | 57 +++++++++++++++++++++++----------------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79aa1eb..b1b6ce3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.5) set(CMAKE_C_FLAGS "-std=c99 -g -Wall") set(CMAKE_INSTALL_PREFIX ".") -#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) include_directories(include) +#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) project(utictactoe) add_executable(${PROJECT_NAME} src/utictactoe.c src/model.c) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8722958..80462b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,5 @@ cmake_minimum_required(VERSION 3.5) set(CMAKE_C_FLAGS "-std=c99 -g -Wall") set(CMAKE_INSTALL_PREFIX ".") include_directories(../include) - project(utictactoe) add_executable(${PROJECT_NAME} utictactoe.c model.c) diff --git a/src/model.c b/src/model.c index 78ad746..af633ef 100644 --- a/src/model.c +++ b/src/model.c @@ -198,39 +198,40 @@ void set_tictactoe_winner(s_tictactoe *p_ttt){ return; } } - } + - /* - * second diagonal, from the end of line - */ - if ( i == TICTACTOE_WIDTH - 1 ) { + /* + * second diagonal, from the end of line + */ + if ( i == TICTACTOE_WIDTH - 1 ) { + find = true; + for ( int l = 1; l < TICTACTOE_WIDTH; l++){ + next = (TICTACTOE_WIDTH - 1) * l; + if ( p_ttt->content[i] == p_ttt->content[next] ) { + find = false; + break; + } + } + if ( find == true ){ + p_ttt->winner = p_ttt->content[i]; + return; + } + } + + /* + * column + */ find = true; - for ( int l = 1; l < TICTACTOE_WIDTH; l++){ - next = (TICTACTOE_WIDTH - 1) * l; - if ( p_ttt->content[i] == p_ttt->content[next] ) { + for (int c = 1; c < TICTACTOE_WIDTH; c++ ) { + next = TICTACTOE_WIDTH * c + i; + if ( p_ttt->content[i] != p_ttt->content[next]) { find = false; break; } - } - if ( find == true ){ - p_ttt->winner = p_ttt->content[i]; - return; - } - } - - /* - * column - */ - find = true; - for (int c = 1; c < TICTACTOE_WIDTH; c++ ) { - next = TICTACTOE_WIDTH * c + i; - if ( p_ttt->content[i] != p_ttt->content[next]) { - find = false; - break; - } - if ( find == true ){ - p_ttt->winner = p_ttt->content[i]; - return; + if ( find == true ){ + p_ttt->winner = p_ttt->content[i]; + return; + } } }