[2022][ruby][9.x] refactoring

pull/1/head
Alpha Chen 2 years ago
parent 3782908dbb
commit cdbcffdda5
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -19,15 +19,15 @@ class Snake
end end
@knots[0] = @knots[0].zip(delta).map { _1 + _2 } @knots[0] = @knots[0].zip(delta).map { _1 + _2 }
(0...@knots.size-1).each do |i| @knots = @knots[1..].inject([@knots[0]]) {|knots, tail|
head = @knots[i] head = knots.last
tail = @knots[i+1]
delta = head.zip(tail).map { _1 - _2 } delta = head.zip(tail).map { _1 - _2 }
if delta.any? { _1.abs > 1 } knots << if delta.any? { _1.abs > 1 }
@knots[i+1] = tail.zip(delta.map { _1.clamp(-1, 1) }).map { _1 + _2 } tail.zip(delta.map { _1.clamp(-1, 1) }).map { _1 + _2 }
end else
tail
end end
}
end end
end end

Loading…
Cancel
Save