R: Rover.constructor use copy() on state

This commit is contained in:
Paul Hameteman 2025-10-14 23:02:00 +02:00
commit eb63607e53
2 changed files with 8 additions and 5 deletions

View file

@ -4,9 +4,12 @@ class Rover {
constructor(commands: String) {
val command = commands.split(' ')
if (command.size >= ROVER_MINIMUM_NEEDED_COMMANDS) {
state.positionX = command[ROVER_STARTING_POSITION_X].toInt()
state.positionY = command[ROVER_STARTING_POSITION_Y].toInt()
state.heading = Heading.from(command[ROVER_FACING_DIRECTION][ROVER_COMMANDLIST_DIRECTION]) ?: Heading.NORTH
state =
state.copy(
positionX = command[ROVER_STARTING_POSITION_X].toInt(),
positionY = command[ROVER_STARTING_POSITION_Y].toInt(),
heading = Heading.from(command[ROVER_FACING_DIRECTION][ROVER_COMMANDLIST_DIRECTION]) ?: state.heading,
)
}
}