Jelly, 23 bytes
UZ Ç¡=⁶$Þ€Ç$⁴¡ZU$⁵+⁴¤¡Y I'm a bit unsatisfied, but MATL needed some competition. :P
Uses the order URDL. Inputs:
- the input array as an array of padded lines
- the number of repetitions
- the move to start from (1 =
U, 2 =R, 3 =D, 4 =L)
###Explanation
UZ Helper link. Argument: A (the 2D array) U Reverse each line and... Z ...transpose. Rotates 90° CCW. Ç¡=⁶$Þ€Ç$⁴¡ZU$⁵+⁴¤¡Y Main link. Arguments: A, n (2D array, repetitions) Ç Rotate 90° CCW... ¡ ...m times. (m = which move to start on) Þ Sort... € ...each line of the array... =⁶ ...based on the characters' equality to " ". Ç Rotate 90° CCW. $ Combine the sort and rotate to one action. ⁴¡ Do that n times. (n = repetition count) Z Transpose and... U ...reverse each line. Rotates 90° CW. $ Combine the transpose and reverse to one action. ¡ Do that... ⁵+⁴¤ ...m + n times. Y Join the array by newlines.