Log Browser > index.php | |
Recent files:
|
File contains 3205
lines and was last altered on Jul 1 2020
Showing the last 500 lines of this file ( 20 lines 200 lines 500 lines ) $cnt = 1; # do header echo "<html>"; if ( $cnt_done < $cnt_all ) { print( '<meta http-equiv="refresh" ' . 'content="30;url=http://www.checkmypages.com/sudoku/index.php?action=Batch1">' . "\n" ); } echo " <body link=#3333FF alink=#3333FF vlink=#3333FF bgcolor=$background_color> <a href=$web_page>Back</a>\n"; if ( $action == 'Batch' or $action == 'Batch1' ) { $sql = "select board,state from sudoku_pos where created_time > now()"; } else { $sql = "select board,state from sudoku_pos order by state"; $cnt_done = 0; } $result = run_sql( $sql ); while( list( $str,$level ) = mysql_fetch_row( $result ) and time() - $start_time < 20 ) { $orig = explode(',',$str); restart_puzzle(); echo "<hr><br><table width=99%><tr><td width=25%><center> <a href=$web_page?action=Get&level=$level&str=$str>$level puzzle " . ($cnt + $cnt_done ) . " of $cnt_all </a> </center> <table border=1>"; for( $c=0;$c<9;$c++ ) { echo "<tr>"; for( $i=0; $i<9;$i ++ ) { echo "<td bgcolor=$col_0_play width=14 height=14>"; $p=$c*9 + $i; if ( $orig[$p] > 0 ) { print( $orig[$p] ); } else { print( "." ); } echo "</td>"; } print( "</tr>\n" ); } print( "</table>\n" ); $cnt ++; if ( $action == 'Batch' or $action == 'Batch1' ) { # ZZZ complete_puzzle(); echo "</td><td valign=top width=30%><ul>\n"; $msg = ereg_replace( '^.*left>', '<br>', $msg ); $tmp = explode( '<br>',$msg ); $c = 0; foreach( $tmp as $t ) { if ( $c > ( count($tmp) /2) ) { echo "</ul></font></td><td valign=top width=30%><font size=-3><ul>\n"; $c=0; } if ( strlen($t) > 5 and ereg( '[A-Z]',$t ) ) { if ( ereg( 'Finished', $t) ) { $t = "$t " . show_difficulty( $difficulty ); } echo "<li>$t\n"; $c++; } } echo "</ul></font></td></tr></table>\n"; $level = show_difficulty( $difficulty ); $sql = "update sudoku_pos set created_time=now(), state='$level' where board='$str'"; run_sql( $sql ); sleep( 1 ); } echo "</td></tr>\n"; } echo "</table>\n"; echo "</body></html>\n"; exit; /* if ( $action == 'Batch' ) { echo "or <a href=$web_page?action=Batch>process more puzzles</a>\n"; $sql = "select board,state from sudoku_pos order by created_time"; } else { $sql = "select board,state from sudoku_pos order by state, created_time"; } $result = run_sql( $sql ); while( list( $str,$level ) = mysql_fetch_row( $result ) ) { restart_puzzle(); $orig = explode(',',$str); echo "<hr><table width=99%><tr><td width=25%><center> <a href=$web_page?action=Get&level=$level&str=$str>$level puzzle $cnt</a> </center> <table border=1>"; for( $c=0;$c<9;$c++ ) { echo "<tr>"; for( $i=0; $i<9;$i ++ ) { echo "<td bgcolor=$col_0_play width=14 height=14>"; $p=$c*9 + $i; if ( $orig[$p] > 0 ) { print( $orig[$p] ); } else { print( "." ); } echo "</td>"; } print( "</tr>\n" ); } print( "</table>\n" ); $cnt ++; if ( $action == 'Batch' ) { complete_puzzle(); echo "</td><td valign=top width=30%><ul>\n"; $msg = ereg_replace( '^.*left>', '<br>', $msg ); $tmp = explode( '<br>',$msg ); $c = 0; foreach( $tmp as $t ) { if ( $c > 30 ) { echo "</ul></font></td><td valign=top width=30%><font size=-3><ul>\n"; $c=0; } if ( strlen($t) > 5 ) { echo "<li>$t\n"; $c++; } } echo "</ul></font></td></tr></table>\n"; $sql = "update sudoku_pos set created_time='" . date( 'Y-m-d' ) . " " . date( 'H:i' ) . "' where board='$str'"; run_sql( $sql ); # stop after 20 secs if ( time() - $start_time > 20 ) { break; } sleep( 1 ); } else { print( "</td><td><table><tr><td><code>" ); for( $c=0;$c<9;$c++ ) { if ( $c % 3 == 0 ) { echo "+---+---+---+<br>\n"; } for( $i=0; $i<9;$i ++ ) { if ( $i %3 == 0 ) { echo "|"; } $p=$c*9 + $i; if ( $orig[$p] > 0 ) { print( $orig[$p] ); } else { print( "." ); } } print( "|<br>\n" ); } echo "+---+---+---+"; echo "</code></td></tr></table></td></tr></table>\n"; } } if ( $action == 'Batch' ) { echo "<a href=$web_page?action=Batch>process more puzzles</a>\n"; } echo "</body></html>\n"; exit; */ } elseif ( $action == 'Save' ) { $mode = 'Play'; $str = get_param( 'str' ); if ( $str > '' ) { # clear board for( $c=0; $c<81; $c++ ) { $orig[$c] = 0; } $str = ereg_replace('[^0-9.-]','',$str); if ( ereg('-',$str) ) { $str = ereg_replace('[.]','0',$str); $str = ereg_replace('[^0-9]','',$str); $orig = $str.split("(?!^)"); } else if ( strlen( $str ) < 200 ) { # if a shorter string then no gaps between digits # clean up the string $str = preg_replace('/\s+/',' ',$str); $str = ereg_replace( '\|','',$str ); $str = ereg_replace( '[+][-]+','',$str ); $str = ereg_replace( '[-]+[+]','',$str ); # search for the most often occuring character # and assume this is the empty square char $bsf_cnt = 0; $bsf_chr = '+'; foreach (count_chars($str, 1) as $i => $val) { if ( $val > $bsf_cnt ) { $bsf_cnt = $val; $bsf_chr = (string) chr($i); } } # remove anuthing other than digits 1-0 and empty square char $keep = '[^' . "1-9${bsf_chr}" . ']'; $str = ereg_replace( $keep,'',$str ); # populate the board for( $c=0; $c<81; $c++ ) { if ( substr( $str,$c,1 ) == $bsf_chr || strlen( $str ) < $c) { $orig[$c] = 0; } else { $orig[$c] = substr( $str,$c,1 ); } } } else { # prepare string $str = ereg_replace( '\|',' ',$str ); $str = preg_replace('/\s+/',' ',$str); $str = trim($str); $words = explode( " ",$str ); $i = 0; $p = 0; $word = current($words); while( $word > '' ) { # get word if ( strlen( $word ) == 1 && $word >= 1 and $word <= 9 ) { $orig[ $p++ ] = $word; } elseif ( $word > 9 or eregi( 'a', $word ) or eregi( '[1-9a].*-', $word ) or in_array( $word, array( '-', '+', '_', '.' ) ) ) { $orig[ $p++ ] = 0; } $word = next($words); } } } restart_puzzle(); save_state($ip); $action = 'Pause'; } elseif ( $value > '' ) { # check square clicked if ( $square >= 0 and $square <= 80 ) { if ( $mode == 'Create' ) { $sq[$square] = array( $value ); $board[$square] = 0; } $flg = 0; foreach( $lines as $line ) { $type = array_shift( $line ); if ( in_array( $square,$line ) ) { foreach( $line as $p ) { if ( $board[$p] == $value ) { $flg = 1; $msg = "<font color=red>There is a $value already " . "in that $type</font>"; } } } } if ( $flg == 0 ) { play_move( $square,$value ); if ( $mode == 'Create' ) { $pos = array(99); $val = array(99); $orig = $board; $square = ($square + 1) %81; } } } else { $msg = "<font color=red>You must select a square and then choose a value</font>"; } } elseif ( $action == 'Empty' && $square >= 0 ) { if ( $square >= 0 and $square <= 80 and $board[$square] > 0 && ( in_array( $square,$pos ) or count($pos) == 1 ) ) { $board[$square] = 0; $orig[$square] = 0; init_options(); if ( count($pos) == 1 ) { $action = 'Create'; } else { $action = 'Pause'; } # remove from playlist $tmp = array_search( $square, $pos ); if ( $tmp > 0 ) { $pos[$tmp] = 82; $val[$tmp] = 0; } save_state($ip); } } elseif ( $action == 'Next' ) { $str = get_param( 'str' ); $level = 'Next'; $mode = 'Play'; create_new_sudoku( $str ); $action = 'Pause'; } elseif ( $action == 'Restart' ) { $mode = 'Play'; restart_puzzle(); $orig[83] = time(); } elseif ( $action == 'Normal' ) { $mode = 'Play'; $last_move = -1; $info_screen = 0; $mode='Play'; } elseif ( $action == 'Hint' ) { $orig[83]=-1; if ( $mode != 'Info' ) { $mode = 'Info'; $last_move = -1; $info_screen = 1; $old_sq = $sq; $old_pos = $pos; $old_val = $val; $old_board = $board; $old_orig = $orig; make_a_move( 4 ); $sq = $old_sq; $pos = $old_pos; $val = $old_val; $board = $old_board; $orig = $old_orig; # show hint if ( finished() ) { $msg = "The puzzle is finished !"; } elseif ( $last_move == -1 ) { $msg = ereg_replace( ').*$', ')Can you see a move here?',$msg ); } else { $msg = "($last_move)Can you see a move here?"; } $orig[83]=-1; } else { $mode='Play'; } } elseif ( $action == 'Play' || $action == 'Step' ) { $mode = 'Play'; $orig[83]=-1; # square is set to 99 on first call so we can reset the board if ( $action == 'Step' && $square != 99 ) { restart_puzzle(); $square = 0; $total_comp_time = 0; $msg = 'Sit back and watch the puzzle get solved'; } else { $last_move = -1; $prev_opt_cnt = count_options_left(); $start_time = time(); make_a_move( 4 ); $total_comp_time += (time() - $start_time); } if ( $testing ) { echo $last_move; } if ( finished() ) { save_in_db( 0 ); if ( ! finished() ) { $msg = "Oh dear, I'm stuck !!!"; } else { $msg = "finished !"; log_msg( $msg ); } $action = 'Pause'; } } elseif ( $action == 'Create' or $action == 'Clear' ) { $mode = 'Create'; $orig[83]=-1; if ( $action == 'Clear' ) { for( $c=0; $c<81; $c++ ) { $board[$c] = 0; $orig[$c] = 0; } init_options(); $action = 'Create'; } $pos = array(99); $val = array(99); $orig = $board; $orig[81] = ''; $msg = "To edit select squares and enter starting values"; } save_state($ip); start_screen_html(); print_board( ); print( "<input type=hidden name=mode value=$mode>" ); if ( $action == 'About' ) { $mode = 'Play'; $action = 'Pause'; } end_screen_html(); ?> |