public void TestRotate3() { var point = new Point(4, 3); var pivot = new Point(2, 4); var actual = point.RotateClockwise(pivot); Assert.AreEqual(4, actual.Col); Assert.AreEqual(6, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(1, actual.Col); Assert.AreEqual(7, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(-1, actual.Col); Assert.AreEqual(5, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(0, actual.Col); Assert.AreEqual(2, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(2, actual.Col); Assert.AreEqual(1, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(4, actual.Col); Assert.AreEqual(3, actual.Row); }
public void TestRotate() { var point = new Point(-1, 0); var pivot = new Point(0, 0); var actual = point.RotateClockwise(pivot); Assert.AreEqual(-1, actual.Col); Assert.AreEqual(-1, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(0, actual.Col); Assert.AreEqual(-1, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(1, actual.Col); Assert.AreEqual(0, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(0, actual.Col); Assert.AreEqual(1, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(-1, actual.Col); Assert.AreEqual(1, actual.Row); actual = actual.RotateClockwise(pivot); Assert.AreEqual(-1, actual.Col); Assert.AreEqual(0, actual.Row); }
private int CalcDensity(Board board, Point[] points) { var ret = 0; for (int i = 0; i < points.Length; i++) { var point = points[i]; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { int ni = point.Row + dx, nj = point.Col + dy; if (0 <= ni && ni < board.Height && 0 <= nj && nj < board.Width) { if (board.Field[ni][nj] == CellState.Free) continue; if (IsNeighbors(point, nj, ni)) { ret++; } } } } } return ret; }
public Unit(Point[] points, Point pivotPoint) { var row = points.Min(x => x.Row); var minCol = points.Min(x => x.Col); Points = points.Select(p => p.Move(new Point(minCol, row), new Point(0, 0))).ToArray(); PivotPoint = pivotPoint.Move(new Point(minCol, row), new Point(0, 0)); }
public static Unit Create(Point pivotPoint, Point[] points) { return new Unit(points, pivotPoint); }
private bool IsNeighbors(Point point1, int col2, int row2) { var point2 = new Point(col2, row2); if (Commands.Any(c => point1.MakeStep(c).Equals(point2.Row, point2.Col))) return true; if (Commands.Any(c => point2.MakeStep(c).Equals(point1.Row, point1.Col))) return true; return false; }