Ludii Forum
Nonempty cells treated as empty - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Problems (https://ludii.games/forums/forumdisplay.php?fid=5)
+--- Forum: Game Problems (https://ludii.games/forums/forumdisplay.php?fid=17)
+--- Thread: Nonempty cells treated as empty (/showthread.php?tid=516)



Nonempty cells treated as empty - Michael - 03-23-2021

In the attached game there is an add-move. Here is the define:
Code:
(define "Deploy"
    (move Add (piece (id "Hex" Mover))
        (to
            (intersection
                (sites Empty)
                (union
                    (sites Mover)
                    (sites Around
                        (sites Occupied by:Mover component:"Hex")
                    )
                )
            )
        )
        (then
            (add (piece (id "Disc" Mover))
                (to (last To))
                stack:true
            )
        )
    )
)
Notice that the to-region is an intersection with (sites Empty). Therefore, it should only be possible to add to empty sites. However, while generating random trials to check the logic of the game, I came across several instances of pieces being added to nonempty sites. The very last move of the included trial is an example. I have no idea how this can have happened, and I have not been able to reproduce it in a simpler version of the game. Any ideas?


RE: Nonempty cells treated as empty - Eric Piette - 03-23-2021

Hi,

I will check why a bit later but in the meantime you can just do the following define which is safer and more efficient than using (sites Empty) here.

Code:
(define "Deploy"
    (move Add (piece (id "Hex" Mover))
        (to
                (union
                    (sites Mover)
                    (sites Around
                        (sites Occupied by:Mover component:"Hex")
                    )
                )
                if:(is Empty (to))
        )
        (then
            (add (piece (id "Disc" Mover))
                (to (last To))
                stack:true
            )
        )
    )
)

Regards,
Eric


RE: Nonempty cells treated as empty - Michael - 03-23-2021

Thanks! That seems to make everything fine :)
Is there a rule of thumb for what ought to go in the region function and what ought to go in the if-parameter of (to) and (from)?


RE: Nonempty cells treated as empty - Eric Piette - 03-23-2021

Hi,

In reality here, the (sites Empty) should work, that's probably just a bug related to the stack state, I will check and fix it when I will time to do it.

For your question, not really, except when of course a region has no sense for the moves because that's implied by the move type (like for the step moves, that's implied by the directions of the move), in which case only a condition will work.

But I think if I would have to give you a kind of rule, when the region is not state dependent (like (sites Board) or (sites Top)) that's better to use a RegionFunction because we pre-compute them, so its use is instantaneous compare to a BooleanFunction which will be run at each state to compute the next legal moves. But when the region is not static (so dependent of a state like (sites Empty)) a condition is better, because you do not need to compute all the empty sites but only the sites you need and check if they are empty.

Regards,
Eric