R: Rover.constructor use copy() on state
This commit is contained in:
parent
b1d82fe8fd
commit
eb63607e53
2 changed files with 8 additions and 5 deletions
|
|
@ -11,8 +11,8 @@
|
|||
- [ ] Rover.turnLeft use copy() on state
|
||||
- [ ] Rover.turnRight use copy() on state
|
||||
- [ ] Rover.move use copy() on state
|
||||
- [ ] Rover.constructor use copy() on state
|
||||
- [ ] Change RoverState to Data Class
|
||||
- [x] Rover.constructor use copy() on state
|
||||
- [x] Change RoverState to Data Class
|
||||
|
||||
# RPP
|
||||
- [ ] Refine Abstractions
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue