R: Finish refine abstractions (add moveBy to position class and use in RS)
This commit is contained in:
parent
65444e0932
commit
af40a996fe
4 changed files with 15 additions and 11 deletions
20
TECHDEBT.md
20
TECHDEBT.md
|
|
@ -1,14 +1,14 @@
|
||||||
# TODO
|
# TODO
|
||||||
- [ ] Refine Abstractions
|
- [x] Refine Abstractions
|
||||||
- [ ] long parameter list
|
- [x] long parameter list
|
||||||
- [ ] data clump
|
- [x] data clump
|
||||||
- [ ] primitive obsession
|
- [x] primitive obsession
|
||||||
- [ ] middle man
|
- [x] middle man
|
||||||
|
|
||||||
# Mikado
|
# Mikado
|
||||||
- [x] Replace x, y with Position in Heading.move()
|
- [x] remove move() from heading
|
||||||
- [x] RoverState.move use position
|
- [x] use position.moveBy in RoverState.move
|
||||||
- [x] Return position in move() instead of Pair
|
- [x] add moveBy to Position class
|
||||||
|
|
||||||
# RPP
|
# RPP
|
||||||
- [ ] Design Patterns
|
- [ ] Design Patterns
|
||||||
|
|
@ -63,3 +63,7 @@
|
||||||
- [x] use position in move()
|
- [x] use position in move()
|
||||||
- [x] Add position to RoverState
|
- [x] Add position to RoverState
|
||||||
- [x] Create Position data class
|
- [x] Create Position data class
|
||||||
|
- [x] Replace x, y with Position in Heading.move()
|
||||||
|
- [x] RoverState.move use position
|
||||||
|
- [x] Return position in move() instead of Pair
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@ enum class Heading(val symbol: Char, val vector: Vector) {
|
||||||
NORTH -> EAST
|
NORTH -> EAST
|
||||||
}
|
}
|
||||||
|
|
||||||
fun move(position: Position): Position = position.copy(x = position.x + vector.deltaX, position.y + vector.deltaY)
|
|
||||||
|
|
||||||
override fun toString(): String = symbol.toString()
|
override fun toString(): String = symbol.toString()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,7 @@ data class Position(
|
||||||
val x: Int = 0,
|
val x: Int = 0,
|
||||||
val y: Int = 0,
|
val y: Int = 0,
|
||||||
) {
|
) {
|
||||||
|
fun moveBy(vector: Vector): Position = copy(x = x + vector.deltaX, y = y + vector.deltaY)
|
||||||
|
|
||||||
override fun toString(): String = "$x $y"
|
override fun toString(): String = "$x $y"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,5 @@ data class RoverState(
|
||||||
|
|
||||||
fun turnRight(): RoverState = copy(heading = heading.turnRight())
|
fun turnRight(): RoverState = copy(heading = heading.turnRight())
|
||||||
|
|
||||||
fun move(): RoverState = copy(position = heading.move(position))
|
fun move(): RoverState = copy(position = position.moveBy(heading.vector))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue