/// <summary> /// Moves the robot to the exit /// </summary> /// <remarks> /// This function uses methods of the robot that was passed into this class' /// constructor. It has to move the robot until the robot's event /// <see cref="IRobot.ReachedExit"/> is fired. If the algorithm finds out that /// the exit is not reachable, it has to call <see cref="IRobot.HaltAndCatchFire"/> /// and exit. /// </remarks> public void MoveRobotToExit() { var reachedEnd = false; robot.ReachedExit += (_, __) => reachedEnd = true; bool[] GetPossibleMoveDirections(Coordinates coordinates) { var neighbours = new bool[4]; for (var x = 0; x < 4; x++) { var direction = (Direction)x; var canMove = robot.CanIMove(direction); neighbours[x] = canMove; if (canMove) { map.TryAdd(coordinates.GetNeighbour(direction), null); } } return(neighbours); } void MakeNextMove(Coordinates coordinates) { if (reachedEnd) { return; }