Ludii Forum
Ludeme needed for distance to nearest piece from site (in specified directions) - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Suggestions (https://ludii.games/forums/forumdisplay.php?fid=10)
+--- Forum: Ludii Features / Services (https://ludii.games/forums/forumdisplay.php?fid=11)
+--- Thread: Ludeme needed for distance to nearest piece from site (in specified directions) (/showthread.php?tid=200)



Ludeme needed for distance to nearest piece from site (in specified directions) - dale walton - 10-06-2020

Currently I have some code that selects all spaces and decides what piece to play based on the criterion of how many of each player's pieces are at the same distance as the nearest piece from the targeted empty location. It is very slow, and it fails when there are selected locations that do not meet the criterion. (The program is showing them as choices for selection, even though there is no subsequent board action)

To solve that I need to select for just the sites I actually want to place on, instead of filtering at the end. But to do this requires procedural steps within the select construct.  (and probably nested forEach Site constructs)

Thus, I would appreciate a ludeme for finding the distance to the nearest piece from a site in any grid direction, (w/ options for limiting it to other directions.)

An option for (count ...) for counting components of a particular type at a particular distance and a particular set of directions would also be much appreciated.


RE: Ludeme needed for distance to nearest piece from site (in specified directions) - Eric Piette - 10-06-2020

Hi Dale,

>> Thus, I would appreciate a ludeme for finding the distance to the nearest piece from a site in any grid direction, (w/ options for limiting it to other directions.)

That is not possible in the current release version, but we already implemented it in our dev version. Consequently, you will be able to do that with the next release. Here an example of what you want:


Code:
(min
    (results
        from:(last To)
        to:(sites LineOfSight at:(from) All)
        (count Steps All (from) (to))
    )
)

Here, we get the minimum distance from the last 'to' site. to any piece in the line of sight from that site in All the directions.



>> An option for (count ...) for counting components of a particular type at a particular distance and a particular set of directions would also be much appreciated.


That is already possible with the current version. Here an example of a such thing:


Code:
(count
    in:(intersection
        (forEach
             (sites LineOfSight at:(last To) Orthogonal)
             if:(= 2 (count Steps Orthogonal (from) (to)))
        )
        (sites Occupied by:Next component:"Ball")
    )
)

Here we count the number of sites occupied by the next player with only components called "Ball" in the line of sight of the last 'to' site played in looking only the Orthogonal directions and we keep only the distance equals to 2.

Regards,
Eric Piette


RE: Ludeme needed for distance to nearest piece from site (in specified directions) - dale walton - 10-08-2020

Good to  know.  So "results" is the new feature?



So this code:




(count

    in:(intersection

        (sites Occupied by:Next component:"Ball")

        (forEach

            (sites LineOfSight at:(last To) Orthogonal)


            if:(=

                (min

                    (results

                        from:(last To)

                        to:(sites LineOfSight at:(from) All)

                        (count Steps All (from) (to))

                    )

                ) 

                (count Steps Orthogonal (from) (to))

            )

        )

    )

)





would then give the number of balls, among those pieces closest to the given site, correct? 




This is on a hex grid.  Does Orthogonal refer to a square grid, or does it refer to sequential cell-to-cell grid lines? 




Does Adjacent mean continuing in the initially adjacent directions, or mean continuing outward in branched adjacent steps (Manhattan distance for example), or mean adjacent branching in all directions, hence all locations within the distance as well?


RE: Ludeme needed for distance to nearest piece from site (in specified directions) - Eric Piette - 10-08-2020

Hi,

Yes "Results" in a new IntArray Ludeme generating an array of integers of all the results of a function between each 'from' site of a region and each 'to' site of another region.

That's better for you to wait the next release to try to use it.

The definition of Orthogonal used in Ludii is: All the directions between two sites sharing at least one edge
The definition of Adjacent used in Ludii is: All the directions between two sites sharing at least one vertex.

Regards,
Eric Piette


RE: Ludeme needed for distance to nearest piece from site (in specified directions) - dale walton - 10-08-2020

Great! I look forward to this feature! Will it be soon until the next release?

When used for more than a single step do Orthogonal and Adjacent continue in a relatively forward direction, or in every applicable direction?


RE: Ludeme needed for distance to nearest piece from site (in specified directions) - Eric Piette - 10-09-2020

Hi Dale,

We did not have a date for the next release. Maybe during the next week.

When you use a radial you mean? (a succession of steps in the same direction). In that case yes we follow for each direction from the origin each radial of each Orthogonal or Adjacent direction. e.g. the move of a queen is a slide in all the adjacent directions and the move of a rook, a slide in all the orthogonal directions.

Regards,
Eric


RE: Ludeme needed for distance to nearest piece from site (in specified directions) - dale walton - 10-11-2020

How do I select sites that are within a certain number of steppings to adjacent empty positions. I wouldn't want to implement this as a series of step moves because one should be able to choose any destination as a single choice, not a series of choices. Is there currently a way to select for this?

Note that it is not the same as all empty sites within a certain distance, because other pieces may block access (no hops) and cause diversions that lengthen the path.


RE: Ludeme needed for distance to nearest piece from site (in specified directions) - Eric Piette - 10-12-2020

Hi Dale,

I am not sure of what exactly you asked. Can you give an example with pieces (ideally with a .lud) and tell me what you except to return (with the list of sites) for one or two pieces in this game.

Regards,
Eric