Untitled
unknown
plain_text
a year ago
3.6 kB
7
Indexable
sealed class CompassDirection { object North : CompassDirection() object South : CompassDirection() object East : CompassDirection() object West : CompassDirection() object Northeast : CompassDirection() object Northwest : CompassDirection() object Southeast : CompassDirection() object Southwest : CompassDirection() object None : CompassDirection() } object FindTagRouter { private val directionMap = mapOf( CompassDirection.North to mapOf( CompassDirection.East to 270, CompassDirection.Northeast to 315, CompassDirection.Northwest to 45, CompassDirection.Southeast to 225, CompassDirection.Southwest to 135, CompassDirection.West to 90, CompassDirection.South to 180 ), CompassDirection.South to mapOf( CompassDirection.East to 90, CompassDirection.North to 180, CompassDirection.Northeast to 135, CompassDirection.Northwest to 225, CompassDirection.Southeast to 45, CompassDirection.Southwest to 315, CompassDirection.West to 270 ), CompassDirection.East to mapOf( CompassDirection.North to 90, CompassDirection.Northeast to 45, CompassDirection.Northwest to 135, CompassDirection.Southeast to 315, CompassDirection.Southwest to 225, CompassDirection.West to 180, CompassDirection.South to 270 ), CompassDirection.West to mapOf( CompassDirection.North to 270, CompassDirection.Northeast to 225, CompassDirection.Northwest to 315, CompassDirection.Southeast to 135, CompassDirection.Southwest to 45, CompassDirection.East to 180, CompassDirection.South to 90 ), CompassDirection.Northeast to mapOf( CompassDirection.North to 45, CompassDirection.East to 315, CompassDirection.Northwest to 90, CompassDirection.Southeast to 270, CompassDirection.Southwest to 180, CompassDirection.West to 225, CompassDirection.South to 135 ), CompassDirection.Northwest to mapOf( CompassDirection.North to 315, CompassDirection.East to 225, CompassDirection.Northeast to 270, CompassDirection.Southeast to 180, CompassDirection.Southwest to 90, CompassDirection.West to 45, CompassDirection.South to 225 ), CompassDirection.Southeast to mapOf( CompassDirection.North to 135, CompassDirection.East to 45, CompassDirection.Northeast to 90, CompassDirection.Northwest to 225, CompassDirection.Southwest to 315, CompassDirection.West to 270, CompassDirection.South to 45 ), CompassDirection.Southwest to mapOf( CompassDirection.North to 225, CompassDirection.East to 135, CompassDirection.Northeast to 180, CompassDirection.Northwest to 270, CompassDirection.Southeast to 45, CompassDirection.West to 90, CompassDirection.South to 315 ) ) fun route(currentDirection: CompassDirection, bestDirection: CompassDirection): Int { if (currentDirection == bestDirection) return 0 return directionMap[bestDirection]?.get(currentDirection) ?: 0 } }
Editor is loading...
Leave a Comment