diff --git a/TECHDEBT.md b/TECHDEBT.md index 49e1998..809f442 100644 --- a/TECHDEBT.md +++ b/TECHDEBT.md @@ -6,11 +6,13 @@ - [ ] middle man # Mikado -- [x] Remove deltaX, deltaY in Heading - - [x] NORTH, etc -> Vector(0, 1) - - [x] move -> return Pair but using vector - - [x] Add Vector to enum class Heading - - [x] Create Vector data class +- [x] Remove posX, posY from RoverState + - [x] use position in Rover.position + - [x] Create toString in Position + - [x] use position in Rover constructor() + - [x] use position in move() + - [x] Add position to RoverState + - [x] Create Position data class # RPP - [ ] Design Patterns @@ -53,3 +55,8 @@ - [x] Rover.move use copy() on state - [x] Rover.constructor use copy() on state - [x] Change RoverState to Data Class +- [x] Remove deltaX, deltaY in Heading + - [x] NORTH, etc -> Vector(0, 1) + - [x] move -> return Pair but using vector + - [x] Add Vector to enum class Heading + - [x] Create Vector data class diff --git a/src/main/kotlin/org/example/Position.kt b/src/main/kotlin/org/example/Position.kt new file mode 100644 index 0000000..75cc7cc --- /dev/null +++ b/src/main/kotlin/org/example/Position.kt @@ -0,0 +1,8 @@ +package org.example + +data class Position( + val x: Int = 0, + val y: Int = 0, +) { + override fun toString(): String = "$x $y" +} diff --git a/src/main/kotlin/org/example/Rover.kt b/src/main/kotlin/org/example/Rover.kt index d930e30..cb501fe 100644 --- a/src/main/kotlin/org/example/Rover.kt +++ b/src/main/kotlin/org/example/Rover.kt @@ -4,11 +4,12 @@ class Rover { constructor(commands: String) { val command = commands.split(' ') if (command.size >= ROVER_MINIMUM_NEEDED_COMMANDS) { - state = - state.copy( - positionX = command[ROVER_STARTING_POSITION_X].toInt(), - positionY = command[ROVER_STARTING_POSITION_Y].toInt(), + val position = + Position( + x = command[ROVER_STARTING_POSITION_X].toInt(), + y = command[ROVER_STARTING_POSITION_Y].toInt(), ) + state = state.copy(position = position) Heading.from(command[ROVER_FACING_DIRECTION][ROVER_COMMANDLIST_DIRECTION])?.let { state = state.copy(heading = it) } @@ -28,7 +29,7 @@ class Rover { } val position: String - get() = "${state.positionX} ${state.positionY} ${state.heading}" + get() = "${state.position} ${state.heading}" fun pos(): String = position diff --git a/src/main/kotlin/org/example/RoverState.kt b/src/main/kotlin/org/example/RoverState.kt index 18f63a5..702e9dd 100644 --- a/src/main/kotlin/org/example/RoverState.kt +++ b/src/main/kotlin/org/example/RoverState.kt @@ -1,8 +1,7 @@ package org.example data class RoverState( - val positionX: Int = 0, - val positionY: Int = 0, + val position: Position = Position(), var heading: Heading = Heading.NORTH, ) { fun turnLeft(): RoverState = copy(heading = heading.turnLeft()) @@ -10,7 +9,7 @@ data class RoverState( fun turnRight(): RoverState = copy(heading = heading.turnRight()) fun move(): RoverState { - val (newX, newY) = heading.move(positionX, positionY) - return copy(positionX = newX, positionY = newY) + val (newX, newY) = heading.move(position.x, position.y) + return copy(position = Position(newX, newY)) } }