public void Run() { GlobalConfig.Writer.Write("Testing T_Position..."); Position pos1 = new Position(5, 3); Position pos2 = new Position(5, 3); Position pos3 = new Position(3, 5); Position pos4 = new Position(5, 4); Position pos5 = new Position(5, 2); Position pos6 = new Position(4, 3); Position pos7 = new Position(6, 3); // IsNeighbour Debug.Assert(!pos1.IsNeighbour(pos2)); Debug.Assert(!pos1.IsNeighbour(pos3)); Debug.Assert(pos1.IsNeighbour(pos4)); Debug.Assert(pos1.IsNeighbour(pos5)); Debug.Assert(pos1.IsNeighbour(pos6)); Debug.Assert(pos1.IsNeighbour(pos7)); // Equals Debug.Assert(pos1.Equals(pos1)); Debug.Assert(pos1.Equals(pos2)); Debug.Assert(!pos1.Equals(pos3)); Debug.Assert(!pos1.Equals(pos4)); Debug.Assert(!pos1.Equals(pos6)); // ToString() Debug.Assert(pos1.ToString().Equals("5;3")); GlobalConfig.Writer.WriteLine("finished"); }
public bool IsNeighbour(Position position) { return ((I == position.I && (J == position.J + 1 || J == position.J - 1)) || (J == position.J && (I == position.I + 1 || I == position.I - 1))); }
private void GetLinkFromString(string lineString, Dictionary<Position, Position> links, int lineNumber) { char[] chars = lineString.ToCharArray(); for (int i = 0; i < chars.Length; i+=2) { if (chars[i] != ' ') { Position pos1 = new Position(i / 2, lineNumber); Position pos2 = new Position(i / 2, lineNumber + 1); links.Add(pos1, pos2); links.Add(pos2, pos1); } } }
public bool Equals(Position other) { return (I == other.I && J == other.J); }
private void GetLineFromString(string lineString, List<Cell[]> cells, Dictionary<Position, Position> links) { Cell[] line = new Cell[lineString.Length/2+1]; char[] chars = lineString.ToLower().ToCharArray(); for (int i = 0; i < chars.Length; i++) { line[i / 2] = CreateCellFromChar(chars[i]); if (++i < chars.Length && chars[i] != ' ') { Position pos1 = new Position(i / 2, cells.Count); Position pos2 = new Position(i / 2 + 1, cells.Count); links.Add(pos1, pos2); links.Add(pos2, pos1); } } cells.Add(line); }