本文整理汇总了C#中Cell.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Cell.Equals方法的具体用法?C# Cell.Equals怎么用?C# Cell.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cell
的用法示例。
在下文中一共展示了Cell.Equals方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPath
private static void GetPath(char[,] matrix, Cell start, Cell end, Stack<Cell> path)
{
if (start.Row >= matrix.GetLength(0) || start.Row < 0 || start.Col >= matrix.GetLength(1) || start.Col < 0)
{
return; // the cell is outside the matrix
}
if (matrix[start.Row, start.Col] == '*')
{
return; // the cell is not passable
}
if (start.Equals(end))
{
path.Push(end);
Console.WriteLine("Path: {0}", string.Join(" ", path.Reverse())); // found exit
path.Pop();
return;
}
matrix[start.Row, start.Col] = '*';
path.Push(start);
GetPath(matrix, new Cell(start.Row + 1, start.Col), end, path);
GetPath(matrix, new Cell(start.Row, start.Col + 1), end, path);
GetPath(matrix, new Cell(start.Row - 1, start.Col), end, path);
GetPath(matrix, new Cell(start.Row, start.Col - 1), end, path);
matrix[start.Row, start.Col] = ' ';
path.Pop();
}
示例2: GetPath
private static void GetPath(char[,] matrix, Cell start, Cell end, ref bool foundExit)
{
if (foundExit)
{
return; // already found the solution and other cases are not interesting
}
if (start.Row >= matrix.GetLength(0) || start.Row < 0 || start.Col >= matrix.GetLength(1) || start.Col < 0)
{
return; // the cell is outside the matrix
}
if (matrix[start.Row, start.Col] == '*')
{
return; // the cell is not passable
}
if (start.Equals(end))
{
foundExit = true; // found exit
return;
}
matrix[start.Row, start.Col] = '*';
GetPath(matrix, new Cell(start.Row + 1, start.Col), end, ref foundExit);
GetPath(matrix, new Cell(start.Row, start.Col + 1), end, ref foundExit);
GetPath(matrix, new Cell(start.Row - 1, start.Col), end, ref foundExit);
GetPath(matrix, new Cell(start.Row, start.Col - 1), end, ref foundExit);
matrix[start.Row, start.Col] = ' ';
}
示例3: CellCloneTest
public void CellCloneTest()
{
int row = 3;
int column = 3;
char value = '-';
Cell cell = new Cell(row, column, value);
Assert.IsTrue(cell.Equals(cell.Clone()));
}
示例4: Equals_GivenCellWithSameCoordinates_ReturnsTrue
public void Equals_GivenCellWithSameCoordinates_ReturnsTrue()
{
// arrange
var cell1 = new Cell(3, 4);
var cell2 = new Cell(y: 4, x: 3);
// assert
Assert.IsTrue(
cell1.Equals(cell2),
message: "The cells were not equal.");
}
示例5: Equals_GivenCellWithNotSameCoordinates_ReturnsFalse
public void Equals_GivenCellWithNotSameCoordinates_ReturnsFalse()
{
// arrange
var cell1 = new Cell(3, 4);
var cell2 = new Cell(4, 3);
// assert
Assert.IsFalse(
cell1.Equals(cell2),
message: "The cells were equal.");
}
示例6: probability
public double probability(Cell<Double> sDelta, Cell<Double> s, CS8803AGA.PsychSim.State.Action a)
{
double prob = 0;
List<Cell<Double>> outcomes = possibleOutcomes(s, a);
for (int i = 0; i < outcomes.Count; i++)
{
if (sDelta.Equals(outcomes[i]))
{
prob += distribution[i];
}
}
return prob;
}
示例7: GetNeighborsOf
private IEnumerable<Cell> GetNeighborsOf(Cell cell)
{
List<Cell> neighbors = new List<Cell>();
foreach (int x in Enumerable.Range(-1, 3))
{
foreach (int y in Enumerable.Range(-1, 3))
{
Cell newCell = new Cell(cell.X + x, cell.Y + y);
if (!newCell.Equals(cell))
{
neighbors.Add(newCell);
}
}
}
return neighbors;
}
示例8: ServerMoveCommand
public ServerMoveCommand(Cell from, Cell to)
{
if (from == null)
{
throw new ArgumentNullException(nameof(from));
}
if (to == null)
{
throw new ArgumentNullException(nameof(to));
}
if (from.Equals(to))
{
throw new ApplicationException("Cannot move unit from one cell to the same cell.");
}
From = from;
To = to;
}
示例9: ToggleHighlightSpawnPath
/// <summary>
///
/// </summary>
/// <param name="c"></param>
/// <param name="turnOn"></param>
public void ToggleHighlightSpawnPath(Cell c, bool turnOn)
{
foreach (string index in this.Position.Keys)
{
Cell cell = this.Position[index];
cell.GetComponent<MeshRenderer>().material.color = SelectionColor;
}
if (turnOn)
{
if (!c.Equals (this.Position ["LeftBottom"])) {
Node n = Board.Instance.Graph[c.X, c.Y];
List<Node> returnList = new List<Node>();
returnList.Add(n);
returnList = FindSpawnPath(n, returnList);
foreach (Node node in returnList)
{
if (!Board.Instance.Grid[node.X, node.Y].IsOccupied && !IsOwnCell(node))
{
Board.Instance.Grid[node.X, node.Y].GetComponent<MeshRenderer>().material.color = Color.yellow;
}
}
} else {
ToggleHighlightSpawnPath(c, false);
}
}
else
{
foreach (Node node in _spawnMovementRangeNodes)
{
Board.Instance.Grid[node.X, node.Y].GetComponent<MeshRenderer>().material.color = Color.gray;
}
}
}
示例10: MoveToCell
/// <summary>
///
/// </summary>
/// <param name="cell"></param>
/// <returns></returns>
public IEnumerator MoveToCell(Cell cell)
{
if (!this.TurnOver)
{
if (!cell.Equals (this.Position ["LeftBottom"]) &&
_BaseMovementRangeNodes != null &&
_BaseMovementRangeNodes.Contains (Board.Instance.Graph [cell.X, cell.Y]))
{
Board.Instance.BaseMovementMode = true;
Board.Instance.MovingMode = true;
cell.ResetCellValues();
Node n = Board.Instance.Graph[cell.X, cell.Y];
List<Node> path = new List<Node> ();
path.Add (n);
path = FindWalkPath (n, path);
path.Reverse ();
TurnOffRangeIndicator ();
foreach (string index in this.Position.Keys) {
Cell c = this.Position [index];
Node node = Board.Instance.Graph [c.X, c.Y];
c.IsOccupied = false;
c.GetComponent<MeshRenderer>().material.color = c.CellColor;
}
foreach (Node node in path) {
yield return StartCoroutine (MoveNextTile (this.transform.position, new Vector3 (node.X, node.Y, this.gameObject.transform.position.z), 2f, n));
}
CurrentMovement = n.H;
this.SetNewPosition (Board.Instance.Graph [cell.X, cell.Y]);
this.DeselectBase();
Board.Instance.MovingMode = false;
Board.Instance.BaseMovementMode = false;
GameController.Instance.IsDone();
}
}
}
示例11: buildPath
public bool buildPath(Cell startCell, Cell endCell, out Cell[] path)
{
List<PathNode> closedCells = new List<PathNode>();
SortedDictionary<int, List<PathNode>> openCells = new SortedDictionary<int, List<PathNode>>(); // int - priority
PathNode startPath = new PathNode();
startPath.m_cell = startCell;
startPath.m_parentNode = null;
startPath.m_stepsFromStart = 0;
startPath.m_heuristicRating = heuristicRating(startCell, endCell);
List<PathNode> startList = new List<PathNode>();
startList.Add(startPath);
openCells.Add(startPath.m_priority, startList);
bool pathFound = false;
PathNode endPathNode = null;
while (0 < openCells.Count)
{
int key = openCells.Keys.First();
List<PathNode> parentListNodes = openCells[key];
PathNode parentNode = parentListNodes.First();
closedCells.Add(parentNode);
parentListNodes.RemoveAt(0);
if (0 == parentListNodes.Count)
{
openCells.Remove(key);
}
if (endCell.Equals(parentNode.m_cell))
{
pathFound = true;
endPathNode = parentNode;
break;
}
List<Cell> successors = getSuccessors(parentNode.m_cell);
foreach (Cell nextCell in successors)
{
PathNode nextPath = new PathNode();
nextPath.m_cell = nextCell;
nextPath.m_parentNode = parentNode;
nextPath.m_stepsFromStart = parentNode.m_stepsFromStart + 1;
bool cellProcessed = false;
foreach (KeyValuePair<int, List<PathNode>> iterator in openCells)
{
bool stop = false;
List<PathNode> listNodes = iterator.Value;
foreach (PathNode openedNode in listNodes)
{
if (openedNode.m_cell.Equals(nextPath.m_cell))
{
if (nextPath.m_stepsFromStart < openedNode.m_stepsFromStart)
{
openCells.Remove(iterator.Key);
}
else
{
cellProcessed = true;
}
stop = true;
break;
}
}
if (stop)
break;
}
if (cellProcessed)
continue;
foreach (PathNode closedNode in closedCells)
{
if (closedNode.m_cell.Equals(nextPath.m_cell))
{
cellProcessed = true;
break;
}
}
if (cellProcessed)
continue;
nextPath.m_heuristicRating = heuristicRating(nextCell, endCell);
if (openCells.ContainsKey(nextPath.m_priority))
{
openCells[nextPath.m_priority].Add(nextPath);
}
else
{
List<PathNode> listNode = new List<PathNode>();
listNode.Add(nextPath);
openCells.Add(nextPath.m_priority, listNode);
}
}
}
//.........这里部分代码省略.........
示例12: GetFastestPath
public Stack<Cell> GetFastestPath(Cell start, Cell target)
{
if (target == null)
{
throw new Exception("target is null.");
}
if (walkableCellTypes.Contains(target.type) == false)
throw new Exception("Cannot move to an unwalkable cell.");
_openList.Clear();
_closedList.Clear();
SetManhattenDist(start.address, target.address);
start.g = 0;
//the estimation of going from target cell to target cell is 0 of course.
target.h = 0;
Stack<Cell> cells = new Stack<Cell>();
if (!start.Equals(target))
{
_openList.Push(start);
while (true)
{
Cell c;
try { c = _openList.Pop(); }
catch (IndexOutOfRangeException e)
{
e.ToString();
break;
}
if (c == null)
break;
//if we havent already checked out the cell c
if (!_closedList.Contains(c))
{
List<Cell> neighbours = MethodLibrary.FindNeighbourCells(_map, c.x, c.y, false, false);
foreach (Cell cc in neighbours)
{
if (cc == null)
continue;
if (walkableCellTypes.Contains(cc.type) && !_closedList.Contains(cc))
{
int dist = Mathf.Abs(cc.address.x - c.address.x) != Mathf.Abs(cc.address.y - c.address.y) ? 14 : 10;
if (c.g + dist < cc.g)
{
cc.g = c.g + dist;
cc.parent = c;
cc.f = c.g + c.h;
}
if (!_openList.Contains(cc))
_openList.Push(cc);
}
} _closedList.Add(c);
}
if (c.address.Equals(target.address))
{
cells.Push(c);
while (c.parent != null && !c.parent.Equals(start))
{
c = c.parent;
cells.Push(c);
}
break;
}
}
}
return cells;
}
示例13: ObjectEquals_GivenCellWithNotSameType_ReturnsFalse
public void ObjectEquals_GivenCellWithNotSameType_ReturnsFalse()
{
// arrange
var cell = new Cell(3, 4);
var notACell = new object();
// assert
Assert.IsFalse(
cell.Equals(notACell),
message: "The objects were equal.");
}