R: Data clump position in Heading/ RoverState
This commit is contained in:
parent
61a4d417b8
commit
65444e0932
3 changed files with 12 additions and 15 deletions
17
TECHDEBT.md
17
TECHDEBT.md
|
|
@ -6,13 +6,9 @@
|
||||||
- [ ] middle man
|
- [ ] middle man
|
||||||
|
|
||||||
# Mikado
|
# Mikado
|
||||||
- [x] Remove posX, posY from RoverState
|
- [x] Replace x, y with Position in Heading.move()
|
||||||
- [x] use position in Rover.position
|
- [x] RoverState.move use position
|
||||||
- [x] Create toString in Position
|
- [x] Return position in move() instead of Pair
|
||||||
- [x] use position in Rover constructor()
|
|
||||||
- [x] use position in move()
|
|
||||||
- [x] Add position to RoverState
|
|
||||||
- [x] Create Position data class
|
|
||||||
|
|
||||||
# RPP
|
# RPP
|
||||||
- [ ] Design Patterns
|
- [ ] Design Patterns
|
||||||
|
|
@ -60,3 +56,10 @@
|
||||||
- [x] move -> return Pair but using vector
|
- [x] move -> return Pair but using vector
|
||||||
- [x] Add Vector to enum class Heading
|
- [x] Add Vector to enum class Heading
|
||||||
- [x] Create Vector data class
|
- [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
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,7 @@ enum class Heading(val symbol: Char, val vector: Vector) {
|
||||||
NORTH -> EAST
|
NORTH -> EAST
|
||||||
}
|
}
|
||||||
|
|
||||||
fun move(
|
fun move(position: Position): Position = position.copy(x = position.x + vector.deltaX, position.y + vector.deltaY)
|
||||||
x: Int,
|
|
||||||
y: Int,
|
|
||||||
): Pair<Int, Int> = Pair(x + vector.deltaX, y + vector.deltaY)
|
|
||||||
|
|
||||||
override fun toString(): String = symbol.toString()
|
override fun toString(): String = symbol.toString()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,5 @@ data class RoverState(
|
||||||
|
|
||||||
fun turnRight(): RoverState = copy(heading = heading.turnRight())
|
fun turnRight(): RoverState = copy(heading = heading.turnRight())
|
||||||
|
|
||||||
fun move(): RoverState {
|
fun move(): RoverState = copy(position = heading.move(position))
|
||||||
val (newX, newY) = heading.move(position.x, position.y)
|
|
||||||
return copy(position = Position(newX, newY))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue