Beispiel #1
0
        private static State MoveToTheLeft(int[,] initState, int[,] goalState, int x, int y)
        {
            if (y == 0)
            {
                return(null);
            }

            var childMatrix = CopyMatrix(initState);

            var temp = childMatrix[x, y - 1];

            childMatrix[x, y - 1] = 0;
            childMatrix[x, y]     = temp;
            int manhatanDistance = CalculateHeuristics.ManhatanDistance(childMatrix, goalState);
            int misplacedeTiles  = CalculateHeuristics.CalculateMisplacedTiles(childMatrix, goalState);

            return(new State(childMatrix, manhatanDistance, misplacedeTiles, ""));
        }
Beispiel #2
0
        private static State MoveToDown(int[,] initState, int[,] goalState, int x, int y)
        {
            if (x == (initState.Length / 3) - 1)
            {
                return(null);
            }

            var childMatrix = CopyMatrix(initState);

            var temp = childMatrix[x + 1, y];

            childMatrix[x + 1, y] = 0;
            childMatrix[x, y]     = temp;
            int manhatanDistance = CalculateHeuristics.ManhatanDistance(childMatrix, goalState);
            int misplacedeTiles  = CalculateHeuristics.CalculateMisplacedTiles(childMatrix, goalState);

            return(new State(childMatrix, manhatanDistance, misplacedeTiles, ""));
        }