sudoko 0.6.0

A comprehensive Sudoku solving library with multiple strategies, puzzle generation, and WebAssembly support
Documentation
use sudoko::{Sudoku, SudokuSolver, YWing, XYWing, SolvingStrategy};

fn main() {
    println!("Testing Y-Wing and XY-Wing with Specific Pattern Puzzles");
    println!("{}", "=".repeat(65));
    
    // Test puzzle specifically designed to have Y-Wing patterns
    // This is a more advanced puzzle that requires Y-Wing/XY-Wing techniques
    let y_wing_puzzle = "000000000904607000076804100637000000000080000000000249008306070000709800000000000";
    
    println!("Testing Y-Wing Pattern Recognition:");
    println!("{}", "-".repeat(40));
    
    let mut puzzle = Sudoku::from_string(y_wing_puzzle, 9).unwrap();
    println!("Original puzzle:");
    println!("{}", puzzle);
    
    // Apply basic strategies first to set up the Y-Wing pattern
    let mut solver = SudokuSolver::new();
    let basic_strategies = vec![
        Box::new(sudoko::NakedSingles) as Box<dyn SolvingStrategy>,
        Box::new(sudoko::HiddenSingles) as Box<dyn SolvingStrategy>,
    ];
    
    for strategy in basic_strategies {
        while strategy.apply(&mut puzzle) {
            println!("Applied {} strategy", strategy.name());
        }
    }
    
    println!("\nAfter basic strategies:");
    println!("{}", puzzle);
    
    // Now test advanced strategies
    let y_wing = YWing;
    let xy_wing = XYWing;
    
    println!("\nTesting Y-Wing:");
    if y_wing.apply(&mut puzzle) {
        println!("✅ Y-Wing pattern found and applied!");
    } else {
        println!("ℹ️  No Y-Wing patterns found");
    }
    
    println!("\nTesting XY-Wing:");
    if xy_wing.apply(&mut puzzle) {
        println!("✅ XY-Wing pattern found and applied!");
    } else {
        println!("ℹ️  No XY-Wing patterns found");
    }
    
    // Show candidate analysis for better understanding
    println!("\n{}", "=".repeat(65));
    println!("Candidate Analysis for Advanced Strategy Detection:");
    println!("{}", "=".repeat(65));
    
    let mut bi_value_cells = Vec::new();
    for row in 0..puzzle.size {
        for col in 0..puzzle.size {
            if puzzle.get(row, col).unwrap().is_empty() {
                let candidates = puzzle.get_candidates(row, col);
                if candidates.len() == 2 {
                    let values: Vec<u8> = candidates.into_iter().collect();
                    bi_value_cells.push((row, col, values.clone()));
                    println!("Cell ({}, {}): candidates {:?}", row + 1, col + 1, values);
                }
            }
        }
    }
    
    if bi_value_cells.len() >= 3 {
        println!("\n✅ Found {} bi-value cells - good for Y-Wing/XY-Wing patterns!", bi_value_cells.len());
        println!("💡 Bi-value cells are essential for advanced wing strategies");
    } else {
        println!("\n⚠️  Only {} bi-value cells found - need at least 3 for wing patterns", bi_value_cells.len());
    }
    
    // Demonstrate the solving power
    println!("\n{}", "=".repeat(65));
    println!("Complete Solve with All Strategies:");
    println!("{}", "=".repeat(65));
    
    let original = Sudoku::from_string(y_wing_puzzle, 9).unwrap();
    match solver.solve_with_stats(original) {
        Ok((solution, stats)) => {
            println!("✅ Puzzle solved!");
            println!("\nFinal solution:");
            println!("{}", solution);
            
            println!("\n📊 Solver Statistics:");
            println!("• Iterations: {}", stats.iterations);
            println!("• Cells filled: {}", stats.cells_filled);
            println!("• Backtrack steps: {}", stats.backtrack_steps);
            
            println!("\n🧠 Strategies Usage:");
            for (strategy, count) in &stats.strategies_used {
                if *count > 0 {
                    println!("{}: {} applications", strategy, count);
                }
            }
            
            if stats.strategies_used.iter().any(|(name, count)| 
                (*name == "Y-Wing" || *name == "XY-Wing") && *count > 0) {
                println!("\n🎉 Advanced wing strategies were used in solving!");
            } else {
                println!("\n📝 This puzzle was solved with basic strategies only");
                println!("   Try more challenging puzzles to see wing patterns in action");
            }
        }
        Err(e) => {
            println!("❌ Failed to solve: {}", e);
        }
    }
    
    println!("\n{}", "=".repeat(65));
    println!("🎓 Educational Notes:");
    println!("{}", "=".repeat(65));
    println!("• Y-Wing and XY-Wing are advanced logical techniques");
    println!("• They work by finding chains of bi-value cells (cells with exactly 2 candidates)");
    println!("• These strategies can eliminate candidates without guessing");
    println!("• They're particularly useful in harder puzzles where basic strategies fail");
    println!("• The solver now includes these techniques in its strategy arsenal!");
}