Ludii Forum
(count Steps) returns 1000000000 - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Questions (https://ludii.games/forums/forumdisplay.php?fid=13)
+--- Forum: About the Ludii Grammar (https://ludii.games/forums/forumdisplay.php?fid=15)
+--- Thread: (count Steps) returns 1000000000 (/showthread.php?tid=511)



(count Steps) returns 1000000000 - Michael - 03-17-2021

Code:
        (count Steps
            (step (to if:(is Empty (to))))
            (last From)
            (last To)
        )
The code above returned 1000000000. In reality, (last From) was 3 steps away from (last To).
The problem does not occur if I don't use the <step> parameter. My question is why this happens.

I have attached a game and a trial. The code is a mess but the relevant parts should be readable. After moving the score should be set to the number of steps the piece moved.


RE: (count Steps) returns 1000000000 - Eric Piette - 03-18-2021

Hi,

After looking your trial, the result is correct. Because you try to compute the distance between (last From) and (last To) in looking only the empty to site. However the site (last To) contains a piece. So (last To) can never be reached here. Consequently the ludeme returns our INFINITY value which is 1000000000.

Regards,
Eric


RE: (count Steps) returns 1000000000 - Michael - 03-18-2021

(03-18-2021, 10:05 AM)Eric Piette Wrote: Hi,

After looking your trial, the result is correct. Because you try to compute the distance between (last From) and (last To) in looking only the empty to site. However the site (last To) contains a piece. So (last To) can never be reached here. Consequently the ludeme returns our INFINITY value which is 1000000000.

Regards,
Eric
Ah, thanks! Should be easy enough to fix :)


RE: (count Steps) returns 1000000000 - Michael - 03-18-2021

Well, I thought it was going to be easy to fix by changing the boolean to (or (is Empty (to)) (= (to) (last To))), but when that didn't work I realized that even setting the if-parameter to True returns infinity.. Even not setting it to anything. The only way I can get it to return anything other than infinity is to remove the (step)-parameter entirely.


RE: (count Steps) returns 1000000000 - Eric Piette - 03-19-2021

Hi,

I just tried on your example that description:

Code:
(count Steps
      (step (to if:(or (= (last To) (to)) (is Empty (to)))))
      (last From)
      (last To)
)

And that works as expected (got 3 for your example which is the right distance with these steps between (last From) and (last To)).
I know I improved recently the code for this ludeme, but maybe I also fixed something without to be aware about it, so if that does not work for you with the current version, that will work with the next version for sure.

Regards,
Eric


RE: (count Steps) returns 1000000000 - Michael - 03-19-2021

Ok, thanks! I think I was using version 1.1.15, so that might be it.