<commit_before><?php

namespace CoenMooij\Sudoku;

use CoenMooij\Sudoku\Generator\HintGenerator;
use CoenMooij\Sudoku\Generator\PuzzleGenerator;
use CoenMooij\Sudoku\Generator\SolutionGenerator;
use CoenMooij\Sudoku\Puzzle\Difficulty;
use CoenMooij\Sudoku\Puzzle\Location;
use CoenMooij\Sudoku\Puzzle\Puzzle;
use CoenMooij\Sudoku\Solver\BacktrackSolver;
use CoenMooij\Sudoku\Solver\SimpleSolver;
use CoenMooij\Sudoku\Validator\GridValidator;

class SudokuService
{
    /**
     * @var SimpleSolver
     */
    private $simpleSolver;
    /**
     * @var SolutionGenerator
     */
    private $solutionGenerator;
    /**
     * @var PuzzleGenerator
     */
    private $puzzleGenerator;
    /**
     * @var BacktrackSolver
     */
    private $backtrackSolver;
    /**
     * @var HintGenerator
     */
    private $hintGenerator;

    public function __construct(
        HintGenerator $hintGenerator,
        SolutionGenerator $solutionGenerator,
        PuzzleGenerator $puzzleGenerator,
        BacktrackSolver $backtrackSolver,
        SimpleSolver $simpleSolver
    ) {
        $this->hintGenerator = $hintGenerator;
        $this->solutionGenerator = $solutionGenerator;
        $this->puzzleGenerator = $puzzleGenerator;
        $this->backtrackSolver = $backtrackSolver;
        $this->simpleSolver = $simpleSolver;
    }

    public function getHint(Puzzle $puzzle): Location
    {
        return $this->hintGenerator->generateOne($puzzle->getGrid());
    }

    /**
     * @return Location[]
     */
    public function getHints(Puzzle $puzzle): array
    {
        return $this->hintGenerator->generateAll($puzzle->getGrid());
    }

    public function simpleSolve(Puzzle $puzzle): Puzzle
    {
        $grid = $this->simpleSolver->solve($puzzle->getGrid());
        $puzzle->setGrid($grid);

        return $puzzle;
    }

    public function solve(Puzzle $puzzle): Puzzle
    {
        $grid = $this->simpleSolver->solve($puzzle->getGrid());

        if ($grid->numberOfEmptyValues() > 0) {
            $grid = $this->backtrackSolver->solve($grid);
        }
        $puzzle->setGrid($grid);<commit_msg>rename grid from solver to solvedGrid<commit_after><?php

namespace CoenMooij\Sudoku;

use CoenMooij\Sudoku\Generator\HintGenerator;
use CoenMooij\Sudoku\Generator\PuzzleGenerator;
use CoenMooij\Sudoku\Generator\SolutionGenerator;
use CoenMooij\Sudoku\Puzzle\Difficulty;
use CoenMooij\Sudoku\Puzzle\Location;
use CoenMooij\Sudoku\Puzzle\Puzzle;
use CoenMooij\Sudoku\Solver\BacktrackSolver;
use CoenMooij\Sudoku\Solver\SimpleSolver;
use CoenMooij\Sudoku\Validator\GridValidator;

class SudokuService
{
    /**
     * @var SimpleSolver
     */
    private $simpleSolver;
    /**
     * @var SolutionGenerator
     */
    private $solutionGenerator;
    /**
     * @var PuzzleGenerator
     */
    private $puzzleGenerator;
    /**
     * @var BacktrackSolver
     */
    private $backtrackSolver;
    /**
     * @var HintGenerator
     */
    private $hintGenerator;

    public function __construct(
        HintGenerator $hintGenerator,
        SolutionGenerator $solutionGenerator,
        PuzzleGenerator $puzzleGenerator,
        BacktrackSolver $backtrackSolver,
        SimpleSolver $simpleSolver
    ) {
        $this->hintGenerator = $hintGenerator;
        $this->solutionGenerator = $solutionGenerator;
        $this->puzzleGenerator = $puzzleGenerator;
        $this->backtrackSolver = $backtrackSolver;
        $this->simpleSolver = $simpleSolver;
    }

    public function getHint(Puzzle $puzzle): Location
    {
        return $this->hintGenerator->generateOne($puzzle->getGrid());
    }

    /**
     * @return Location[]
     */
    public function getHints(Puzzle $puzzle): array
    {
        return $this->hintGenerator->generateAll($puzzle->getGrid());
    }

    public function simpleSolve(Puzzle $puzzle): Puzzle
    {
        $solvedGrid = $this->simpleSolver->solve($puzzle->getGrid());
        $puzzle->setGrid($solvedGrid);

        return $puzzle;
    }

    public function solve(Puzzle $puzzle): Puzzle
    {
        $grid = $this->simpleSolver->solve($puzzle->getGrid());

        if ($grid->numberOfEmptyValues() > 0) {
            $grid = $this->backtrackSolver->solve($grid);
        }
        $puzzle->setGrid($grid);
{'fraction_non_alphanumeric': 0.1204311152764761, 'fraction_numerical': 0.00046860356138706655, 'mean_word_length': 2.930939226519337, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2059596', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1325, 'n_words': 214}