Ludii Forum
Multiple ways to solve a problem - advice? - 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: Multiple ways to solve a problem - advice? (/showthread.php?tid=99)



Multiple ways to solve a problem - advice? - AlekErickson - 07-30-2020

I am programming a game where new groups are seeded by players every turn, and automatically "grow" at the beginning of each players turn. The code looks like this - which, by the way, is very close to the actual intended game. 




Code:
(game "Inkblot Variant"
    (players 2)
    (equipment 
        {
            (board (tri Hexagon 19))
            (piece "Ball" Each)
        }
    )
    (rules 
        (meta (swap))
        (start (place Random {"Ball2" "Ball1" "Ball2"}))
        (play
            (move Add (to (sites Empty))
                (then (add (to (expand (sites Occupied by:Mover) steps:1 Orthogonal))))
            )
        )
        (end (if (no Moves Next)(byScore {(score P1 (count Pieces P1)) (score P2 (count Pieces P2))})))
    )
)




In the code, players first add a new stone to the board, and then all groups grow. However, the game is intended to be the opposite - first, all of a player's groups automatically grow, and then they place a stone. I have programmed this way because I read that NonDecisions can only come as the effect of a move, or following a player decision. Is there a way to have an effect trigger automatically every turn, followed by a player move? All my attempts to script it failed. Cameron suggested I first check if it is the first turn with (if (= (count Moves) 0)) (move Add (to (sites Empty))) or something similar, so that the game doesn't try to "grow" non-existent groups (I temporarily made a random 3-stone pie to overcome this). But I could not figure out how to place such a check into context, like at what point to perform this check. I looked at the Amazons code and tried to do something similar but it never worked for me. 





Alternatively, I could stick with this Decision --> Effect architecture, but make the effect grow all of the Mover's groups EXCEPT the stone just placed. How could I make exceptions in sites Occupied by Mover to exclude the last stone placed?  





The other way would be to have the growth affect the Next player's groups. However, this results in adding the Mover's stones to the Next player's groups, which is not the desired effect. How could I modify the command above to add the Next player's stones to the Next player's groups? 





Finally, I made a random pie, but it would be nice to have a phase where one player adds all 3 stones intentionally for the other person to choose sides. Is there examples of more complex pie offers already coded in Ludii that I could take a look? 





Thanks for any help. Even if I see a solution for one of these problems, I am interested in all answers to all questions, because it will help me design more Ludii games in the future.


RE: Multiple ways to solve a problem - advice? - cambolbro - 07-30-2020

Hi,

I'd do it as follows:

        (play
            (move Add (to (sites Empty))
                (then
                    (add (piece (id "Disc" Next))         // assumes both players use Disc
                        (to
                            (intersection
                                (expand (sites Occupied by:Next) Orthogonal)
                                (sites Empty)
                            )
                        )
                    )
                )
            )
        )


and just make the group growth an automatic effect of the previous player's turn. This takes liberties with the conceptual delineation of turns, but works well in practice.

If you need to exclude the player's last move, then you could try something along the lines of (difference ... (sites (to)) or (last To). 

Regards,
Cameron


RE: Multiple ways to solve a problem - advice? - cambolbro - 07-30-2020

...and look at Three-Player Hex.lud for examples of more complex swap mechanisms tried as part of a student project.

Regards,
Cameron