Table of Contents

Method GetConnectedLines

Namespace
Gamelogic.Words.Grids
Assembly
Gamelogic.Words.dll

GetConnectedLines<TCell>(IGrid<GridPoint2, TCell>, GridPoint2, Func<GridPoint2, GridPoint2, bool>, Func<GridPoint2, int, bool, GridPoint2>, int)

Gets all the cells in the grid that is connected in a "line" from the given point. Line is defined by an arbitrary function that gives the next point in line, given a current point, the direction, and whether to go forward or backward.

public static IEnumerable<IEnumerable<GridPoint2>> GetConnectedLines<TCell>(IGrid<GridPoint2, TCell> grid, GridPoint2 point, Func<GridPoint2, GridPoint2, bool> isNeighborsConnected, Func<GridPoint2, int, bool, GridPoint2> getNextPoint, int directionCount)

Parameters

grid IGrid<GridPoint2, TCell>

The grid

point GridPoint2

The point to start at

isNeighborsConnected Func<GridPoint2, GridPoint2, bool>

Whether of not neighbors are connected. Neighbors in this case are consecutive points on a line.

getNextPoint Func<GridPoint2, int, bool, GridPoint2>

A function used to traverse lines. It should give the next point in line from the given line in the given direction, either forward or backwards depending on the bool. It is up to the caller to interpret the direction index. This function will be called for all values of the direction index between 0 and one less than the direction count. It does not matter which direction is which index, as long as you handle it consistently. Finaly, if q == getNextPoint(p, n, true), then the following must hold: p == getNextPoint(q, n, false). Here is an example of a function that traverses lines on a rect grid:

public RectPoint GetNextPointInLineOnRectGrid(RectPoint p, int directionIndex, bool forward)
{
switch(directionIndex)
{
case 0: return point + forward?RectPoint.North, RectPoint.South;
case 1: return point + forward?RectPoint.West, RectPoint.East;
case 2: return point + forward?RectPoint.South, RectPoint.North;
case 3: return point + forward?RectPoint.East, RectPoint.West;
}

             	throw(new IllegalArgumentException);
             }</code></pre></example>
directionCount int

How many line directions there are at each point. For example, hex grids have 6 for typical lines

Returns

IEnumerable<IEnumerable<GridPoint2>>

Type Parameters

TCell

The cell type of the grid

GetConnectedLines<TCell>(IGrid<GridPoint2, TCell>, GridPoint2, Func<GridPoint2, GridPoint2, bool>)

Gets all the cells in the grid that is connected in a "line" from the given point.

public static IEnumerable<IEnumerable<GridPoint2>> GetConnectedLines<TCell>(IGrid<GridPoint2, TCell> grid, GridPoint2 point, Func<GridPoint2, GridPoint2, bool> isNeighborsConnected)

Parameters

grid IGrid<GridPoint2, TCell>

The grid

point GridPoint2

The point to start at

isNeighborsConnected Func<GridPoint2, GridPoint2, bool>

Whether of not neighbors are connected

Returns

IEnumerable<IEnumerable<GridPoint2>>

Type Parameters

TCell

The cell type of the grid