public string AlphabetBoardPath(string target) { char answerSymbol = '!'; int previousX = 0, previousY = 0; StringBuilder stringBuilder = new StringBuilder(); char alphabetA = 'a'; _previousCoordinate.SetCoordinate(previousX, previousY); _movingMan.SetPreviousAlphabetCoordinate(_previousCoordinate); foreach (char alphabetNow in target) { // Get coordinate via ASCII table int currentX = (alphabetNow - alphabetA) % 5; int currentY = (alphabetNow - alphabetA) / 5; _currentCoordinate.SetCoordinate(currentX, currentY); _movingMan.SetCurrentAlphabetCoordinate(_currentCoordinate); _movingMan.SetStringBuilder(stringBuilder); if (currentX == previousX && currentY == previousY) { stringBuilder.Append(answerSymbol); } else { // Moving order is important _movingMan.MoveUp() .MoveRight() .MoveLeft() .MoveDown(); stringBuilder.Append(answerSymbol); previousX = currentX; previousY = currentY; _previousCoordinate.SetCoordinate(previousX, previousY); } } var output = _movingMan.GetDestinyOutPut(); //_log.LogInformation($"Solution output: {output}"); return(output); }