diff --git a/TECHDEBT.md b/TECHDEBT.md index a6a3143..f6b4d03 100644 --- a/TECHDEBT.md +++ b/TECHDEBT.md @@ -7,7 +7,7 @@ - [ ] Clean up constants and private fields - [ ] Move move() into Heading.move(Position) - [ ] Move turnLeft() into Heading.turnLeft() - - [ ] Move turnRight() into Heading.turnRight() + - [x] Move turnRight() into Heading.turnRight() - [x] Remove HEADING_* constants - [x] in move() compare to heading enum - [x] in turnRight() compare to heading enum diff --git a/src/main/kotlin/org/example/Heading.kt b/src/main/kotlin/org/example/Heading.kt index 18735d6..98d7ece 100644 --- a/src/main/kotlin/org/example/Heading.kt +++ b/src/main/kotlin/org/example/Heading.kt @@ -7,6 +7,13 @@ enum class Heading(val symbol: Char) { WEST('W'), ; + fun turnRight() = when (this) { + EAST -> SOUTH + SOUTH -> WEST + WEST -> NORTH + NORTH -> EAST + } + override fun toString(): String = symbol.toString() companion object { diff --git a/src/main/kotlin/org/example/Rover.kt b/src/main/kotlin/org/example/Rover.kt index b782509..ba57605 100644 --- a/src/main/kotlin/org/example/Rover.kt +++ b/src/main/kotlin/org/example/Rover.kt @@ -30,12 +30,7 @@ class Rover { } private fun turnRight() { - when (state.heading) { - Heading.EAST -> state.heading = Heading.SOUTH - Heading.SOUTH -> state.heading = Heading.WEST - Heading.WEST -> state.heading = Heading.NORTH - Heading.NORTH -> state.heading = Heading.EAST - } + state.heading = state.heading.turnRight() } private fun turnLeft() {