R: Move move() into Heading.move(Position)
This commit is contained in:
parent
4e3d9177af
commit
84e78f18d3
3 changed files with 31 additions and 29 deletions
36
TECHDEBT.md
36
TECHDEBT.md
|
|
@ -1,28 +1,12 @@
|
||||||
# TODO
|
# TODO
|
||||||
- [ ] Complexity
|
|
||||||
- [x] long method
|
|
||||||
- [ ] duplicated code
|
|
||||||
-
|
|
||||||
# Mikado
|
|
||||||
- [ ] Clean up constants and private fields
|
|
||||||
- [ ] Move move() into Heading.move(Position)
|
|
||||||
- [x] Move turnLeft() into Heading.turnLeft()
|
|
||||||
- [x] Move turnRight() into Heading.turnRight()
|
|
||||||
- [x] Remove HEADING_* constants
|
|
||||||
- [x] in move() compare to heading enum
|
|
||||||
- [x] in turnRight() compare to heading enum
|
|
||||||
- [x] in turnLeft() compare to heading enum
|
|
||||||
- [x] state.heading in Rover.constructor to enum
|
|
||||||
- [x] Change heading Char in RoverState to Heading enum
|
|
||||||
- [x] Create Heading enum
|
|
||||||
|
|
||||||
# RPP
|
|
||||||
- [ ] Reorder Responsibilities
|
- [ ] Reorder Responsibilities
|
||||||
- [ ] long class
|
- [ ] long class
|
||||||
- [ ] feature envy
|
- [ ] feature envy
|
||||||
- [ ] inappropriate intimacy
|
- [ ] inappropriate intimacy
|
||||||
- [ ] data class
|
- [ ] data class
|
||||||
- [ ] message chain
|
- [ ] message chain
|
||||||
|
|
||||||
|
# RPP
|
||||||
- [ ] Refine Abstractions
|
- [ ] Refine Abstractions
|
||||||
- [ ] long parameter list
|
- [ ] long parameter list
|
||||||
- [ ] data clump
|
- [ ] data clump
|
||||||
|
|
@ -40,3 +24,19 @@
|
||||||
- [x] bad naming
|
- [x] bad naming
|
||||||
- [x] antipattern
|
- [x] antipattern
|
||||||
- [x] scopes
|
- [x] scopes
|
||||||
|
- [x] Complexity
|
||||||
|
- [x] long method
|
||||||
|
- [x] duplicated code
|
||||||
|
-
|
||||||
|
# Mikado
|
||||||
|
- [x] Clean up constants and private fields
|
||||||
|
- [x] Move move() into Heading.move(Position)
|
||||||
|
- [x] Move turnLeft() into Heading.turnLeft()
|
||||||
|
- [x] Move turnRight() into Heading.turnRight()
|
||||||
|
- [x] Remove HEADING_* constants
|
||||||
|
- [x] in move() compare to heading enum
|
||||||
|
- [x] in turnRight() compare to heading enum
|
||||||
|
- [x] in turnLeft() compare to heading enum
|
||||||
|
- [x] state.heading in Rover.constructor to enum
|
||||||
|
- [x] Change heading Char in RoverState to Heading enum
|
||||||
|
- [x] Create Heading enum
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package org.example
|
package org.example
|
||||||
|
|
||||||
enum class Heading(val symbol: Char) {
|
enum class Heading(val symbol: Char, val deltaX: Int, val deltaY: Int) {
|
||||||
NORTH('N'),
|
NORTH('N', 0, 1),
|
||||||
EAST('E'),
|
EAST('E', 1, 0),
|
||||||
SOUTH('S'),
|
SOUTH('S', 0, -1),
|
||||||
WEST('W'),
|
WEST('W', -1, 0),
|
||||||
;
|
;
|
||||||
|
|
||||||
fun turnLeft(): Heading =
|
fun turnLeft(): Heading =
|
||||||
|
|
@ -23,6 +23,11 @@ enum class Heading(val symbol: Char) {
|
||||||
NORTH -> EAST
|
NORTH -> EAST
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun move(
|
||||||
|
x: Int,
|
||||||
|
y: Int,
|
||||||
|
): Pair<Int, Int> = Pair(x + deltaX, y + deltaY)
|
||||||
|
|
||||||
override fun toString(): String = symbol.toString()
|
override fun toString(): String = symbol.toString()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,9 @@ class Rover {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun move() {
|
private fun move() {
|
||||||
when (state.heading) {
|
val (updatedX, updatedY) = state.heading.move(state.positionX, state.positionY)
|
||||||
Heading.EAST -> state.positionX++
|
state.positionX = updatedX
|
||||||
Heading.SOUTH -> state.positionY--
|
state.positionY = updatedY
|
||||||
Heading.WEST -> state.positionX--
|
|
||||||
Heading.NORTH -> state.positionY++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun turnRight() {
|
private fun turnRight() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue