Taking the dog for a walk My dog is barking at me, but I'm too lazy to take him for a walk. I have an idea! I'll get the people at Code Golf to do it for me!

Your challenge is to simulate a dog's walk. Here are the rules for walking the dog:


The human (H) will start at 0,0 on a (Cartesian) coordinate plane, and will randomly go one space either up, left, right, or down every second.
The dog (D) will start at the same location, and will go either zero, one, two, or three spaces either up, left, right, or down every second (randomly, of course). The dog is less predictable and will sometimes run faster or stop completely.
The dog will never get more than a certain amount of units away from the human (in Euclidean distance), which is the length of the leash (L). For example, if L is 6, a valid position would be H(0,0) D(4,4) (since the distance is about 5.65 units), but not H(0,0) D(5,4) (about 6.4 units).

If, when the dog moves, it would violate the leash distance requirement, it must go the farthest it can in its determined direction that does not violate the distance requirement. For example, if the position is H(0,0) D(3,4) and the dog is randomly decided to move 3 spaces to the right, it will go to D(4,4), since that's the farthest it can go without getting more than 6 units away. (Note that this might result in a movement of 0 spaces, i.e. no movement at all!)

Miscellaneous rules: the human moves first. The human must not exceed the leash length on its move. If it does, it must choose another direction. "Random" means "with an even distribution and with no patterns."


The input will be given in this format (can be STDIN, function parameter, file, etc.):

"&lt;amount of seconds the walk will last&gt; &lt;leash length&gt;"


For example:

300 6 // a 5 minute walk with a 6 yard leash


You must give output in this format (can be STDOUT, function return value, file, etc.):

H(0,0) D(0,0)
H(0,1) D(2,0)
H(1,1) D(2,1)
H(1,0) D(2,-1)
...


(The amount of lines output will be seconds + 1, since the H(0,0) D(0,0) line doesn't count.)

This is code-golf, so the shortest code in bytes will win!
CoffeeScript - 324 + function call

Demo (Using Leash 10):

H(0,0) D(0,0)
H(0,-1) D(0,3)
H(-1,-1) D(0,3)
H(-1,-2) D(-1,3)
H(-1,-3) D(-4,3)
H(-1,-2) D(-4,4)
H(-1,-3) D(-5,4)
H(-1,-2) D(-2,4)
H(-1,-3) D(-2,5)
H(-1,-4) D(-2,5)
H(-1,-3) D(-3,5)
H(0,-3) D(-4,5)
H(-1,-3) D(-4,6)
H(-1,-4) D(-2,6)
H(-2,-4) D(-2,6)
H(-3,-4) D(-5,6)
H(-4,-4) D(-5,6)
H(-4,-3) D(-5,8)
H(-5,-3) D(-2,8)
H(-5,-2) D(-2,8)
H(-5,-3) D(-2,5)


Code:

w=(i)-&gt;
    [s,l]=i.split ' ';m=Math;h=[0,0];d=[0,0];r=-&gt;(4*m.random())|0
    a=-&gt;m.abs(h[0]-d[0])**2+m.abs(h[1]-d[1])**2&lt;=l**2
    b=(x)-&gt;if x%2 then 1else-1
    for i in[0..s]
        console.log "H(#{h}) D(#{d})"
        loop
            H=h.slice();x=r();h[(x/2)|0]+=b x;break if a();h=H
        D=r();x=r();(d[(x/2)|0]+=b x;d[(x/2)|0]-=b x if!a())while D--&gt;0


Long Code:

human = [ 0, 0 ]
doge = [ 0, 0 ]
randomDirection = -&gt; [ 'u', 'd', 'l', 'r' ][(4*Math.random())|0]
allowed = -&gt; Math.abs(human[0] - doge[0]) ** 2 + Math.abs(human[1] - doge[1]) ** 2 &lt;= leash**2
leash = 0
walk = (input) -&gt;
    [ seconds, leash ] = input.split ' '
    for i in [0..seconds]
        console.log "H(#{human}) D(#{doge}) #{Math.sqrt Math.abs(human[0] - doge[0]) ** 2 + Math.abs(human[1] - doge[1]) ** 2}"
        valid = no
        loop
            oldHuman = human.slice()
            switch randomDirection()
                when 'u'
                    human[0]--
                when 'd'
                    human[0]++
                when 'l'
                    human[1]--
                when 'r'
                    human[1]++

            if allowed()
                break
            else
                human = oldHuman

        dogeDistance = (Math.random() * 4)|0
        switch randomDirection()
            when 'u'
                while dogeDistance-- &gt; 0
                    doge[0]--
                    doge[0]++ if !allowed() 
            when 'd'
                while dogeDistance-- &gt; 0
                    doge[0]++
                    doge[0]-- if !allowed() 
            when 'l'
                while dogeDistance-- &gt; 0
                    doge[1]--
                    doge[1]++ if !allowed() 
            when 'r'
                while dogeDistance-- &gt; 0
                    doge[1]++
                    doge[1]-- if !allowed() 
walk "10 2"