arnab
12/02/2016, 6:44 PMnewDirectionIndex
might still be negative. So we’d need to handle that:
val modifierForTurn = (if (turn == Turn.R) 1 else -1)
val currentIndex = directionsInRightTurnOrder.indexOf(heading)
var nextIndex = (currentIndex + modifierForTurn) % directionsInRightTurnOrder.size
nextIndex = if (nextIndex < 0) directionsInRightTurnOrder.size + nextIndex else nextIndex
return directionsInRightTurnOrder[nextIndex]