File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,17 +62,32 @@ def interpret(command)
6262 if move . match? ( command )
6363 case robot . position . f
6464 when 'NORTH'
65- robot . position . y += 1
65+ y = robot . position . y
66+ y += 1
67+ position = Position . new ( robot . position . x , y , robot . position . f )
68+
69+ robot . update_robot ( position ) if table . valid_position? ( robot . position . x , position . y )
6670 when 'EAST'
67- robot . position . x += 1
71+ x = robot . position . x
72+ x += 1
73+
74+ position = Position . new ( x , robot . position . y , robot . position . f )
75+
76+ robot . update_robot ( position ) if table . valid_position? ( position . x , robot . position . y )
6877 when 'SOUTH'
69- robot . position . y -= 1
78+ y = robot . position . y
79+ y -= 1
80+ position = Position . new ( robot . position . x , y , robot . position . f )
81+
82+ robot . update_robot ( position ) if table . valid_position? ( robot . position . x , position . y )
7083 when 'WEST'
71- robot . position . x -= 1
72- end
84+ x = robot . position . x
85+ x -= 1
7386
74- robot . update_robot ( robot . position )
75- puts "New position #{ robot . position . x } ,#{ robot . position . y } ,#{ robot . position . f } "
87+ position = Position . new ( x , robot . position . y , robot . position . f )
88+
89+ robot . update_robot ( position ) if table . valid_position? ( position . x , robot . position . y )
90+ end
7691 end
7792
7893 # puts 'reporting' if report.match?(command)
You can’t perform that action at this time.
0 commit comments