Add a test for i in set_tictactoe_winner()
This commit is contained in:
parent
943e63ee45
commit
c1a0446402
3 changed files with 30 additions and 30 deletions
|
@ -1,7 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
|
set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
|
||||||
set(CMAKE_INSTALL_PREFIX ".")
|
set(CMAKE_INSTALL_PREFIX ".")
|
||||||
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||||
project(utictactoe)
|
project(utictactoe)
|
||||||
add_executable(${PROJECT_NAME} src/utictactoe.c src/model.c)
|
add_executable(${PROJECT_NAME} src/utictactoe.c src/model.c)
|
||||||
|
|
|
@ -2,6 +2,5 @@ cmake_minimum_required(VERSION 3.5)
|
||||||
set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
|
set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
|
||||||
set(CMAKE_INSTALL_PREFIX ".")
|
set(CMAKE_INSTALL_PREFIX ".")
|
||||||
include_directories(../include)
|
include_directories(../include)
|
||||||
|
|
||||||
project(utictactoe)
|
project(utictactoe)
|
||||||
add_executable(${PROJECT_NAME} utictactoe.c model.c)
|
add_executable(${PROJECT_NAME} utictactoe.c model.c)
|
||||||
|
|
57
src/model.c
57
src/model.c
|
@ -198,39 +198,40 @@ void set_tictactoe_winner(s_tictactoe *p_ttt){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* second diagonal, from the end of line
|
/*
|
||||||
*/
|
* second diagonal, from the end of line
|
||||||
if ( i == TICTACTOE_WIDTH - 1 ) {
|
*/
|
||||||
|
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;
|
find = true;
|
||||||
for ( int l = 1; l < TICTACTOE_WIDTH; l++){
|
for (int c = 1; c < TICTACTOE_WIDTH; c++ ) {
|
||||||
next = (TICTACTOE_WIDTH - 1) * l;
|
next = TICTACTOE_WIDTH * c + i;
|
||||||
if ( p_ttt->content[i] == p_ttt->content[next] ) {
|
if ( p_ttt->content[i] != p_ttt->content[next]) {
|
||||||
find = false;
|
find = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
if ( find == true ){
|
||||||
if ( find == true ){
|
p_ttt->winner = p_ttt->content[i];
|
||||||
p_ttt->winner = p_ttt->content[i];
|
return;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue