/
dabuzmakov
/
mazes-task-ulearn
Обзор
Документация
Войти
/
dabuzmakov
/
mazes-task-ulearn
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
DiagonalMazeTask.cs
40 строк
1020 B
da.buzmakov
initial commit
19 окт 2025, 20:35
19 окт 2025, 20:35
f7f14cd
Код
Авторство
О чём код?
using System; namespace Mazes; public static class DiagonalMazeTask { public static void MoveOut(Robot robot, int width, int height) { var aspectRatio = (double)height / width; if (aspectRatio > 1) { var steps = (int)Math.Round(aspectRatio); MoveDiagonal(robot, steps, Direction.Down, Direction.Right); } else { var steps = (int)Math.Round(1.0 / aspectRatio); MoveDiagonal(robot, steps, Direction.Right, Direction.Down); } } public static void MoveStraight(Robot robot, Direction direction, int steps) { for (var i = 0; i < steps; i++) { robot.MoveTo(direction); } } public static void MoveDiagonal(Robot robot, int steps, Direction firstDir, Direction secondDir) { while (true) { MoveStraight(robot, firstDir, steps); if (robot.Finished) break; robot.MoveTo(secondDir); } } }