コード例 #1
0
ファイル: PointTest.cs プロジェクト: Erop147/ICFPC_2015
        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);
        }
コード例 #2
0
ファイル: PointTest.cs プロジェクト: Erop147/ICFPC_2015
        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);
        }
コード例 #3
0
        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;
        }
コード例 #4
0
ファイル: Unit.cs プロジェクト: Erop147/ICFPC_2015
        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));
        }
コード例 #5
0
ファイル: Unit.cs プロジェクト: Erop147/ICFPC_2015
 public static Unit Create(Point pivotPoint, Point[] points)
 {
     return new Unit(points, pivotPoint);
 }
コード例 #6
0
 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;
 }