Created
November 1, 2017 09:43
-
-
Save HoangPV/75930b224c176092d9164e712d2ca4c9 to your computer and use it in GitHub Desktop.
Tic-Tac-Toe Checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = array( | |
array( 1, 0, 0 ), | |
array( 2, 0, 0 ), | |
array( 1, 0, 0 ), | |
); | |
function is_solved( $arr ) { | |
for ( $i = 0; $i < 3; $i ++ ) { | |
if ( $arr[ 0 ][ $i ] == $arr[ 1 ][ $i ] && $arr[ 0 ][ $i ] == $arr[ 2 ][ $i ] && $arr[ 0 ][ $i ] != 0 ) { | |
return $arr[ 0 ][ $i ]; | |
} | |
if ( $arr[ $i ][ 0 ] == $arr[ $i ][ 1 ] && $arr[ $i ][ 0 ] == $arr[ $i ][ 2 ] && $arr[ $i ][ 0 ] != 0 ) { | |
return $arr[ $i ][ 0 ]; | |
} | |
} | |
if ( $arr[ 0 ][ 0 ] == $arr[ 1 ][ 1 ] && $arr[ 0 ][ 0 ] == $arr[ 2 ][ 2 ] && $arr[ 0 ][ 0 ] != 0 ) { | |
return $arr[ 0 ][ 0 ]; | |
} | |
if ( $arr[ 0 ][ 2 ] == $arr[ 1 ][ 1 ] && $arr[ 0 ][ 2 ] == $arr[ 2 ][ 0 ] && $arr[ 0 ][ 2 ] != 0 ) { | |
return $arr[ 0 ][ 2 ]; | |
} | |
return - 1; | |
} | |
$res = is_solved( $arr ); | |
highlight_string( "<?php\n\$data =\n" . var_export( $res, TRUE ) . ";\n?>" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment