Made maze logic orientation-independent