<commit_before>﻿namespace Foat.Puzzles.NPuzzle.Solution
{
    using Foat.Puzzles.Solutions;
    using System;

    public class ManhattanDistance : IHeuristic<NPuzzle>
    {
        public int GetMinimumEstimatedSolutionLength(NPuzzle puzzleInstance)
        {
            int distance = 0;

            for (int y = 0; y < puzzleInstance.N; ++y)
            {
                for (int x = 0; x < puzzleInstance.N; ++x)
                {
                    if (puzzleInstance.GetValue(x, y) != null)
                    {
                        int xGoal;
                        int yGoal;

                        byte? value = puzzleInstance.GetValue(x, y);
                        GetGoalStateIndexForSquareValue(value, puzzleInstance.N, out xGoal, out yGoal);
                        distance += GetSingleManhattanDistance(x, y, xGoal, yGoal);
                    }
                }
            }

            return distance;
        }

        private static void GetGoalStateIndexForSquareValue(byte? value, int n, out int xGoal, out int yGoal)
        {
            if (value.HasValue)
            {
                xGoal = (value.Value - 1) % n;
                yGoal = (value.Value - 1) / n;
            }
            else
            {
                xGoal = n - 1;
                yGoal = xGoal;
            }
        }
<commit_msg>Fixed a tiny bug with the ManhattanDistance that I introduced accidentally when changing the solution state in previous changeset.<commit_after>﻿namespace Foat.Puzzles.NPuzzle.Solution
{
    using Foat.Puzzles.Solutions;
    using System;

    public class ManhattanDistance : IHeuristic<NPuzzle>
    {
        public int GetMinimumEstimatedSolutionLength(NPuzzle puzzleInstance)
        {
            int distance = 0;

            for (int y = 0; y < puzzleInstance.N; ++y)
            {
                for (int x = 0; x < puzzleInstance.N; ++x)
                {
                    if (puzzleInstance.GetValue(x, y) != null)
                    {
                        int xGoal;
                        int yGoal;

                        byte? value = puzzleInstance.GetValue(x, y);
                        GetGoalStateIndexForSquareValue(value, puzzleInstance.N, out xGoal, out yGoal);
                        distance += GetSingleManhattanDistance(x, y, xGoal, yGoal);
                    }
                }
            }

            return distance;
        }

        private static void GetGoalStateIndexForSquareValue(byte? value, int n, out int xGoal, out int yGoal)
        {
            if (value.HasValue)
            {
                xGoal = value.Value % n;
                yGoal = value.Value / n;
            }
            else
            {
                xGoal = n - 1;
                yGoal = xGoal;
            }
        }

{'fraction_non_alphanumeric': 0.07884409561184445, 'fraction_numerical': 0.0035676061362825543, 'mean_word_length': 1.2044025157232705, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '2367547', 'n_tokens_mistral': 807, 'n_tokens_neox': 742, 'n_words': 186}