Get move-able area, or moving path between two chess/tiles on an orthogonal or isometric, or hexagonal board.
Categories > Board > rex_slg_movementIntroductionLinksDependenceUsagePrepareGet moveable areaMain flowFlow chart of getting costFlow chart of filter functionShuffle neighborsCache costGet moving pathMain flowFlow chart of getting costPath modeGet shortest pathGet shorter pathExact or nearestMove chess alone pathUse case of filter function and cost functionNo overlapped with other chessPick enemiesNo moving across enemiesMore samplesWrapAccumulated costFlood fillMore samplesMove on tilemap
This plugin picks tiles of move-able area or moving path into a group. therefor rex_board and rex_ginstgroup objects should be put into project first.
Get move-able area
Action:Get moveable areaAction:Get moveable area by UIDThere are 5 parameters in action
Chess : chess to move.
Moving points : initial moving point. Chess could move to tiles (i.e move-able tiles) when the remaining moving point is large or equal to 0.
Moving cost : each tile will consume some cost. This parameter could be a number or a string
Number : constant moving cost of each tile
String : get cost from cost function. Flow chart of cost function is show above.
Cost function is started at Condition:On cost, to get cost of this moving
Expression:ChessUIDExpression:StartTileUID at LXYZ (Expression:StartX, Expression:StartY)Expression:PreTileUID at LXYZ (Expression:PreTileX, Expression:PreTileY, 0) , with accumulation cost: Expression:PreTilePathCostExpression:TileUID at LXYZ (Expression:TileX, Expression:TileY, 0)Return cost by Action:Set cost
Expression:BLOCKINGFilter : The result of moving area are UID of tiles by default. Or use a filter function if this parameter is not equal to "", to reset or add picked instances. Flow chart of filter function is shown above.
Filter function is started at Condition:On filter
Expression:TileUID at LXYZ : (Expression:TileX, Expression:TileY, 0)Add an instance by uid into result group by Action:Append filter result
Group : put move-able tiles into result group , which is a group in instance group object
Sample capx
If property Shuffle neighbors is set to Yes, the order of visited neighbors will be random, i.e. the order of visited nodes is not the same for each request.
Here is the order of tiles in result group with parameters
Moving points = 3Cost = 1Shuffle neighbors = No
If property Cache cost is set to Yes, Condition:On cost will only be triggered once for each tile in a request.
Get shortest moving path between source chess to destination chess/tile
Action:Get moving pathAction:Get moving path by UIDThere are 5 parameters in action
Chess : source chess.
Tile/Chess : destination chess/tile.
Moving points : initial moving point. Chess could move to tiles (i.e move-able tiles) when the remaining moving point is large or equal to 0.
Moving cost : each tile will consume some cost. This parameter is very similar with parameter Moving cost in Action:Get moveable area.
Number : constant moving cost of each tile
String : get cost from cost function. Flow chart of cost function is show above.
Cost function is started at Condition:On cost, to get cost of this moving
Expression:ChessUIDExpression:StartTileUID at LXYZ (Expression:StartX, Expression:StartY)Expression:PreTileUID at LXYZ (Expression:PreTileX, Expression:PreTileY, 0) , with accumulation cost: Expression:PreTilePathCostExpression:TileUID at LXYZ (Expression:TileX, Expression:TileY, 0)Expression:EndTileUID  at LXYZ (Expression:EndX, Expression:EndY, 0)Return cost by Action:Set cost
Expression:BLOCKINGGroup : pick a path presented by a sequence of tiles into result group , which is a group in instance group object.
Configure property Path mode to get a shorter path or shortest path.
Set property Path mode to 
Random : picking the shortest path randomlyDiagonal : picking the shortest path which has the maximum changing of moving directionStraight : picking the shortest path which has the minimum changing of moving directionLine : picking the shortest path which has the minimum changing of moving angleSet property Path mode to A*-,
A* -line, A* -random : using A* algorithm to find path, this will have the best performance. It is recommended that using these modes only when parameter moving point is set to Expression:INFINITY.Set parameter Exact  to nearest to get moving path from start tile to nearest target tile. Get the nearest target tile UID by Expression:NearestTileUID.
The result of instance group is empty if Exact is set to "" and no path found from start tile to target tile.
Using rex_grid_move behavior to move chess alone path after 	Action:Get moving path.
Action:Get moving pathAdd events of C2 function Move to next tile :
Condition:Pop one instance of Instance group pluginAction:Move to chess of grid move behaviorsystem condition:Else)Add events to move to next tile when reached to target tile by Condition:On hit target position of grid move behavior
Sets propertyForce move toYes in grid move behavior, since the move-able (solid) had been determined 
by this Action:Get moving path.
Uses Expression: PrivateGroup (Instance group plugin) to pick path into private group of chess instance when picking path of multiple chess.
Sample capx This sample capx shows how to implement the filter function and cost function to get move-able area, moving path, and the enemies in a range.
Filter tiles which the cell of chess is empty, to exclude the tiles which has been occupied by other chess.
If (Expression:TileX, Expression:TileY, 0) is empty (Condition:Is empty of board object) under Condition:On filter
Expression:TileUID by Action:Append filter resultAppend enemy instances which stand on tiles, to pick pick enemies in a range.
Pick enemy chess by Condition:Pick chess above tile (board object) under Condition:On filter
Action:Append filter resultReturn Expression:BLOCKING if the enemy instance stands on tile under in cost function
Pick enemy chess by (Expression:TileX, Expression:TileY, 1) (board object) under Condition:On cost
Expression:BLOCKING if trueCache cost is set to NoSample capx
Set property Wrap to Yes in board object to wrap the logical boundary. It will also effect the result of picking move-able area and moving path. Chess could move from left boundary to right boundary directly.
Get accumulated cost from start tile to a specific chess/tile after Action:Get moveable area or Action:Get moving path  by Expression:UID2PathCost (sample capx). Return -1 if this specific chess/tile is not in the last scan of request.

Sample capx
Action:Get moveable area uses  flood fill to find move-able area by Condition:On cost. This feature also could be used to picking neighbor chess/tile which have the same color.
The steps of picking are -
Save target color in variable.
Call Action:Get moveable area, sets the parameter of Moving point to 1.
In Condition:On cost, pick tile/chess instance by Expression:TileUID or (Expression:TileX, Expression:TileY, 0).
Compare the color of picked instance with target color
Action:Set cost if the color of picked instance is equal to target color, . Expression:BLOCKING by default.Add the source tile into result group by Action:Add instances of (Instance group plugin) after Action:Get moveable area.
Sample capx
Sets all tiles (LZ=0) by string symbols, and sets the squareTx to align to the tilemap object. Then uses these string symbol tile in input parameter of Action:Get moveable area or Action:Get moving path, it will pick tiles by string symbols.
Since the results group are not UID of instance in this case, uses 
Condition:For each UID and Expression:Item to retrieve the string symbol for move-able area, or Expression:Pop( group_name , 0) to get string symbol in order for moving path.