![]() |
Sum of minimal distances between two sites - 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: Sum of minimal distances between two sites (/showthread.php?tid=1635) |
Sum of minimal distances between two sites - Alain Busser - 08-04-2023 Hello, with my pupils we tested the included game, played on a graph with pieces set (at start) to the other player's home. The goal is to be the first one to have one's pieces at home (or to block the other player). In the initial version (created by a 6 years old girl) there were too many draws, so we used armbands to restrict the number of moves: every time one moves, one has to give away one armband, until one can not move anymore. In the included file I managed to emulate this armband trick, with stacks of decreasing lengths. The game is interesting but the end condition is not good. What I need is to program what we do with the children: once the game is ended, we compute
Then, the winner is the player who has the smallest sum. If the sums are equal one plays again, until the sums are not equal. The ludeme Code: (count (sites Between from:a to:b)) gives me one unit less than the distance, but I don't know how to apply it to a list of sites, it seems to work only when a and b are sites. So I need
I see in the language reference that forEach is used either to set an action (like Move), or to filter sites (in the Regions functions) but there is no example of use of forEach to get a list of integers. At least I did not find one. So how can I compute a sum of distances to get the score? RE: Sum of minimal distances between two sites - Michael - 08-04-2023 What you want to look up is how to (count Steps). And to sum the distances you can use (+ (results …)), or just (+ {(count Steps …) … }). RE: Sum of minimal distances between two sites - Alain Busser - 08-09-2023 Thank you a lot! But I still don't have it. There's an error with Code: (score P1 Even if I switch the "forEach..." and the "count", or if I include the whole ludeme inside brackets. In the language reference I don't find examples for the use of forEach to retrieve something else than moves or regions. RE: Sum of minimal distances between two sites - Michael - 08-09-2023 You need to use results, I think. This might be wrong, because I'm typing on my phone without consulting the reference, but something like this: Code: (+ RE: Sum of minimal distances between two sites - dale walton - 08-26-2023 (08-09-2023, 03:03 AM)Alain Busser Wrote: Thank you a lot! The results method appears to be the simplest. But I can help with some of your other questions: Your code above fails because "(+" is not an iterative operator for regions or integers. It CAN be used to sum arrays such as in the (result) example because (results ...) is an array. A more cumbersome solution is to store the values into an array using (remember ...) Or else you can use addScore. Code: (forEach Site The biggest problem with all these is that they can't be used in the (score ) statements in the (byScore ...) ludeme in the (end ...) section) because they are processes (moves) rather than integers. So if you used them you would need to ad code in the Play section to do them just in the last turn. The (+ (results ...)) can be used in (score ...) because it is an integer, not the result of moves. Here is how that might look:... Code: (end -------------------------------------- Another question is do you allow passing (but giving up a ring) If so you could do it this way, as an example: Code: (piece "DiscFlat" Each RE: Sum of minimal distances between two sites - Alain Busser - 09-10-2023 (08-26-2023, 07:27 AM)dale walton Wrote: Another question is do you allow passing (but giving up a ring) Actually the idea came to one of my pupils. We didn't try it yet because I was not convinced that the game would be better. Trying your version with the ludii player shows that it is much better:
I'll announce that to the pupils tomorrow, thank you a lot, you considerably enhanced the game. I propose it here although it is not the place. |