R: Rover.move use copy() & make positionX and positionY immutable
This commit is contained in:
parent
eb63607e53
commit
0ca418f0b5
3 changed files with 4 additions and 5 deletions
|
|
@ -25,8 +25,7 @@ class Rover {
|
|||
|
||||
private fun move() {
|
||||
val (updatedX, updatedY) = state.heading.move(state.positionX, state.positionY)
|
||||
state.positionX = updatedX
|
||||
state.positionY = updatedY
|
||||
state = state.copy(positionX = updatedX, positionY = updatedY)
|
||||
}
|
||||
|
||||
private fun turnRight() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package org.example
|
||||
|
||||
data class RoverState(
|
||||
var positionX: Int = 0,
|
||||
var positionY: Int = 0,
|
||||
val positionX: Int = 0,
|
||||
val positionY: Int = 0,
|
||||
var heading: Heading = Heading.NORTH,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue