本文整理汇总了C#中ICell.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# ICell.GetLength方法的具体用法?C# ICell.GetLength怎么用?C# ICell.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICell
的用法示例。
在下文中一共展示了ICell.GetLength方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNode
private static Coordinates? TestNode(ICell[,] grid, int x, int y)
{
int xsize = grid.GetLength(0), ysize = grid.GetLength(1);
if (x >= 0 && x < xsize && y >= 0 && y < ysize && grid[x, y].Weight >= 0 && grid[x, y].Weight < 1)
return grid[x, y].Coordinates;
return null;
}
示例2: MatrixMementoConstructProperMatrix
public void MatrixMementoConstructProperMatrix(int rows, int cols)
{
ICell[,] field = new ICell[rows, cols];
MatrixMemento memento = new MatrixMemento(field);
Assert.AreEqual(field.GetLength(0), memento.Field.GetLength(0), "Memento field expected rows are not equal to actual rows");
Assert.AreEqual(field.GetLength(1), memento.Field.GetLength(1), "Memento field expected cols are not equal to actual cols");
}
示例3: Process
public IEnumerable<ICell> Process(ICell[,] cells, Coordinates from, Coordinates to)
{
try
{
Contract.Requires(cells != null);
Contract.Requires(from.Inside(new Coordinates(cells.GetLength(0), cells.GetLength(1))));
Contract.Requires(to.Inside(new Coordinates(cells.GetLength(0), cells.GetLength(1))));
InitData(cells, from, to);
plannedNodes.Add(startCoord);
while (plannedNodes.Count > 0)
{
//находим в запланированных вершину с наименьшей эвристической стоимостью
var cur = TakeMinimalHeuristic();
//если найденная - пункт назначения, то заканчиваем поиск и начинаем сборку пути
if (cur == goalCoord)
break;
CellData curData = data[cur];
curData.processed = true;
//рассматриваем все с ней смежные, необработанные ранее
var adjList = adjacement.Adjacement(grid, cur);
foreach (Coordinates adj in adjList.Where(c => !data[c].processed))
{
//определяем стоимость смежной вершины на основе уже пройденного пути
double score = curData.scoreCalc + Score(grid.At(adj));
//если вершина не была посещена, или в неё можно прийти более коротким путём - обновляем информацию
bool notFound = !plannedNodes.Contains(adj);
CellData adjData = data[adj];
if (notFound || score < adjData.scoreCalc)
{
adjData.cameFrom = cur;
adjData.scoreCalc = score;
adjData.scoreHeur = score + Heuristic(grid.At(adj));
//если вершина ещё не была посещена - запланируем посещение
if (notFound)
plannedNodes.Add(adj);
}
}
}
return AssemblePath();
}
catch (KeyNotFoundException)
{
throw new IndexOutOfRangeException();
}
}
示例4: Process
public IEnumerable<ICell> Process(ICell[,] cellMap, Coordinates start, Coordinates end)
{
Contract.Requires(cellMap != null);
Contract.Requires(start.Inside(new Coordinates(cellMap.GetLength(0), cellMap.GetLength(1))));
Contract.Requires(end.Inside(new Coordinates(cellMap.GetLength(0), cellMap.GetLength(1))));
DNode[,] dist = new DNode[cellMap.GetLength(0), cellMap.GetLength(1)];
int count = cellMap.GetLength(0) * cellMap.GetLength(1);
for (int i = 0; i < cellMap.GetLength(0); ++i)
for (int j = 0; j < cellMap.GetLength(1); ++j)
dist[i, j] = new DNode();
dist[start.X, start.Y].val = 0;
Coordinates? min = null;
do
{
min = FindMin(dist);
if (min.HasValue)
{
CheckForeign(cellMap, dist, min.Value);
dist[min.Value.X, min.Value.Y].visited = true;
}
} while (min.HasValue);
int waylen = 0;
DNode dnode = dist[end.X, end.Y];
while (dnode.prev.HasValue)
{
++waylen;
dnode = dist[dnode.prev.Value.X, dnode.prev.Value.Y];
}
if (waylen > 0)
{
ICell[] res = new ICell[waylen + 1];
res[waylen] = cellMap[end.X, end.Y];
int i = waylen - 1;
dnode = dist[end.X, end.Y];
while (dnode.prev.HasValue)
{
res[i--] = cellMap[dnode.prev.Value.X, dnode.prev.Value.Y];
dnode = dist[dnode.prev.Value.X, dnode.prev.Value.Y];
}
return res;
}
else
{
return new LinkedList<ICell>();
}
}
示例5: MatrixSaveMementoAndRestoreMementoMethodsWorkProper
public void MatrixSaveMementoAndRestoreMementoMethodsWorkProper()
{
ICell[,] fieldExpected = new ICell[3, 7];
Matrix matrix = new Matrix();
matrix.Field = fieldExpected;
MatrixMemento matrixMemento = matrix.SaveMemento();
matrix.Field = new ICell[12, 18];
matrix.RestoreMemento(matrixMemento); // Comment this row and the test will fail
Assert.AreEqual(fieldExpected.GetLength(0), matrix.Rows, "Matrix SaveMememento and RestoreMememento doesn't work proper");
Assert.AreEqual(fieldExpected.GetLength(1), matrix.Cols, "Matrix SaveMememento and RestoreMememento doesn't work proper");
}
示例6: ProcessTest
public IEnumerable<ICell> ProcessTest(
[PexAssumeUnderTest]global::PathfindingAlgorithms.Algorithms.Astar.Astar target,
ICell[,] cells,
Coordinates from,
Coordinates to
)
{
PexAssume.IsNotNull(cells);
PexAssume.IsTrue(cells.GetLength(0)* cells.GetLength(1) > 0);
PexAssume.IsTrue(from.Inside(new Coordinates(cells.GetLength(0) - 1, cells.GetLength(1) - 1)));
PexAssume.IsTrue(to.Inside(new Coordinates(cells.GetLength(0) - 1, cells.GetLength(1) - 1)));
PexAssume.IsTrue(cells.GetLowerBound(0) == 0);
PexAssume.IsTrue(cells.GetLowerBound(1) == 0);
bool f = true;
for (int x = cells.GetLowerBound(0); x <= cells.GetUpperBound(0); x++)
{
for (int y = cells.GetLowerBound(1); y <= cells.GetUpperBound(1); y++)
{
PexAssume.IsNotNull(cells[x, y]);
PexAssume.IsNotNull(cells[x, y].Coordinates);
f &= cells[x, y].Coordinates.Equals(new Coordinates(x, y));
}
}
PexAssume.IsTrue(f);
IEnumerable<ICell> result = target.Process(cells, from, to);
return result;
// TODO: добавление проверочных утверждений в метод AstarTest.ProcessTest(Astar, ICell[,], Coordinates, Coordinates)
}
示例7: CheckForeign
protected void CheckForeign(ICell[,] cm, DNode[,] d, Coordinates coords)
{
int f = coords.X, s = coords.Y;
double w;
//left
if ((f > 0) && (cm[f - 1, s].Weight >= 0))
{
w = cm[f - 1, s].Weight + d[f, s].val;
if (w < d[f - 1, s].val)
{
d[f - 1, s].val = w;
d[f - 1, s].prev = coords;
}
}
//right
if ((f < cm.GetLength(0) - 1) && (cm[f + 1, s].Weight >= 0))
{
w = cm[f + 1, s].Weight + d[f, s].val;
if (w < d[f + 1, s].val)
{
d[f + 1, s].val = w;
d[f + 1, s].prev = coords;
}
}
//top
if ((s > 0) && (cm[f, s - 1].Weight >= 0))
{
w = cm[f, s - 1].Weight + d[f, s].val;
if (w < d[f, s - 1].val)
{
d[f, s - 1].val = w;
d[f, s - 1].prev = coords;
}
}
//bottom
if ((s < cm.GetLength(1) - 1) && (cm[f, s + 1].Weight >= 0))
{
w = cm[f, s + 1].Weight + d[f, s].val;
if (w < d[f, s + 1].val)
{
d[f, s + 1].val = w;
d[f, s + 1].prev = coords;
}
}
}
示例8: PlayFieldMemento
/// <summary>
/// Constructor for the play field memento.
/// </summary>
/// <param name="playField">Matrix of ICell objects.</param>
/// <param name="playerPosition">Position of the player.</param>
public PlayFieldMemento(ICell[,] playField, IPosition playerPosition)
{
this.playField = new ICell[playField.GetLength(0), playField.GetLength(1)];
this.PlayField = playField;
this.PlayerPosition = playerPosition;
}