Ludii Forum
still not understanding why some rules can't be in the piece definition - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Questions (https://ludii.games/forums/forumdisplay.php?fid=13)
+--- Forum: About Ludii (https://ludii.games/forums/forumdisplay.php?fid=14)
+--- Thread: still not understanding why some rules can't be in the piece definition (/showthread.php?tid=274)



still not understanding why some rules can't be in the piece definition - slimy_asparagus - 11-21-2020

In an earlier thread, Eric said:


(11-02-2020, 09:15 AM)Eric Piette Wrote: The other define "MoveOntoBoard" refers from a set of sites to another. Consequently the moves do not belong to a specific pieces and is better to be directly in the playing rules rather than the pieces themselves.


I still don't get this.

I am attaching test files. One works, the other doesn't. The one that fails, compiles but will not allow me to move the pieces onto the board. Instead it brings up the preferences dialog. My one question is:

Can I move the "MoveOntoBoard" construct into the piece definition (like in test-fails.lud) so it works like in (test-works.lud)? If not why not?

The problem I am having now is that I am trying to introduce the differences between the different sorts of pieces. The natural place for those is in the piece definition hence why I am trying to move all movement definitions there.

The only alternatives I can see is setting a value in each piece definition and then having logic running off that value. That seems quite unnatural and probably less efficient. Ludii does not seem to have a notion of "attribute", which would also be a workable solution for me. I can simulate it using maps or perhaps division and remainder but it would all be clunky.

For a specific example, in this thread I have introduce a map. I would not need if the "MoveOntoBoard" usage could go in the piece definition, because then I could pass a parameter through the macro.

Also in test-fails.lud it allows Pass. It should not allow Pass. I would ask how to prevent that, but I have used up my quota of questions.


RE: still not understanding why some rules can't be in the piece definition - Eric Piette - 11-23-2020

Hi,

The moves described in a piece generator have to be described for each piece individually. That's why in 99% of the case they refer to the ludeme (from) which is used to indicate the position of each piece in iterating them with the ludeme (forEach Piece).

In your fail file, the (from ...) description is not for a single piece, but to move to a set of sites to another.
Consequently for each piece individually all these moves will be computed, which is wrong.

If you want a such description in the moves generator of a piece you need to have a condition for each piece in the (from ...) ludeme.
Moreover the (forEach Piece) refers to a container (by default the board). Consequently if you want to check some pieces which are in another container like the hand of the players you have to specific the container.

Here the full description doing that:

Code:
(define "MoveOntoBoard"
    (move
        (from if:(is In (from) (sites Hand Mover)))
        (to (sites Outer))
    )
)

//-------------------------------------------------------------------------

(game "Test"
    (players 2)
    (equipment {
      (board (rectangle 4 3))
      (piece "Ball" Each ("MoveOntoBoard"))
      (hand Each)
    })
    (rules
      (start {
        (place Stack "Ball1" (handSite P1))
        (place Stack "Ball2" (handSite P2))
      })
      (play
        (forEach Piece container:(mover))
      )
      (end (if (no Moves Next) (result Mover Win)))
    )
)


Regards,
Eric


RE: still not understanding why some rules can't be in the piece definition - slimy_asparagus - 11-23-2020

Eric,

Thanks very much for the help.

Your proposed code works as it is. However when I fold it back into the working code it fails. Simply it allows me to move onto the board but it won't allow me to move within the board.

I attach a new test file that shows this.

Nicholas


RE: still not understanding why some rules can't be in the piece definition - Eric Piette - 11-23-2020

Hi,

Yes you kept only the (forEach Piece container:(mover)), so you check only the pieces in the hands now.

If you want to check the two containers you have to do
(or
(forEach Piece)
(forEach Piece container:(mover))
)

Regards,
Eric


RE: still not understanding why some rules can't be in the piece definition - slimy_asparagus - 11-23-2020

Eric

Thanks. That works and integrates into the working code. I have also managed to make some progress without getting completely stuck which must be a relief to you. But the next bit is complicated. ;-(