Skip to content

Commit b39456f

Browse files
committed
Validate the position of the placed robot against the table coordinates
1 parent 0f842b7 commit b39456f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

toy_robot.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/ruby
22

3+
require_relative './lib/table'
34
require_relative './lib/robot'
45

6+
table = Table.new
57
robot = Robot.new
68

79
# Keep reading user inputs while the program is running
@@ -11,9 +13,10 @@
1113

1214
unless input == 'EXIT'
1315
position = robot.place(input)
14-
puts "Position: #{position.x},#{position.y}"
16+
# Only update robot if the position is valid on the table
17+
robot.update_robot(position) if table.valid_position?(position.x, position.y)
1518

16-
robot.update_robot(position)
19+
puts "Position: #{position.x},#{position.y}"
1720

1821
puts 'placed' unless robot.not_in_place?
1922
next

0 commit comments

Comments
 (0)