Beispiel #1
0
 public override void GatherPathStats(GamePath gamePath, Board board)
 {
     gamePath.MaxArea   = (float)MaxArea.MaximalRectangle(board.Cells) / 64;
     gamePath.FragScore = Fragmentation.GetFragmentationScore(board.Cells);
     //here the gamePath get the result from the addition function
     gamePath.Tsiun = GetMaxArea(board);
 }
Beispiel #2
0
        /// <summary>
        /// 面积选择的方法
        /// </summary>
        /// <param name="hv_image">输入的图像</param>
        /// <param name="trackBarMin">低阈值的滚动条</param>
        /// <param name="trackBarMax">高阈值的滚动条</param>
        /// <param name="MinFlag">指示该方法是否是低阈值在滚动</param>
        /// <param name="tbox">返回另一个阈值的读数</param>
        /// <param name="MinArea">输出的低阈值对应的面积</param>
        /// <param name="MaxArea">输出的高阈值对应的面积</param>
        /// <returns></returns>

        public string AreaShape(HObject hv_image, TrackBar trackBarMin, TrackBar trackBarMax, bool MinFlag, TextBox tbox, out int MinArea, out int MaxArea)
        {
            HObject Region, ho_ConnectedRegions = null, ho_SelectedRegions = null;

            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
            ////分为 面积区域的选择  和  threshold 选择
            HOperatorSet.Threshold(hv_image, out Region, _ThresholdMin, _ThresholdMax);
            string value;

            MinArea = trackBarMin.Value;
            MaxArea = trackBarMax.Value;



            if (MinFlag)
            {
                value = trackBarMin.Value.ToString();
                if (MinArea > MaxArea)
                {
                    trackBarMax.Value = MinArea;
                    trackBarMin.Value = MinArea;
                    MaxArea           = MinArea;
                    tbox.Text         = MinArea.ToString();
                }
            }
            else
            {
                value = trackBarMax.Value.ToString();
                if (MinArea > MaxArea)
                {
                    trackBarMax.Value = MaxArea;
                    trackBarMin.Value = MaxArea;
                    MinArea           = MaxArea;
                    tbox.Text         = MaxArea.ToString();
                }
            }
            //存储合适的面积大小
            _AreaMin = MinArea;
            _AreaMax = MaxArea;

            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "fill");
                //HOperatorSet.Rgb1ToGray(halcon_image, out ho_GrayImage);
                HOperatorSet.Connection(Region, out ho_ConnectedRegions);
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                         "and", MinArea, MaxArea);
                //halcon code    显示图片
                HOperatorSet.DispObj(hv_image, HDevWindowStack.GetActive());
                //halcon code   显示区域
                HOperatorSet.DispObj(ho_SelectedRegions, HDevWindowStack.GetActive());
            }
            //释放
            ho_SelectedRegions.Dispose();
            ho_ConnectedRegions.Dispose();
            Region.Dispose();
            return(value);
        }
Beispiel #3
0
        public void TwoDiagonalCornerCells()
        {
            Board board = new Board();

            board.Cells[0][0] = true;
            board.Cells[7][7] = true;

            Assert.AreEqual(49, MaxArea.MaximalRectangle(board.Cells));
        }
Beispiel #4
0
        public void HalfAndMoreOfAllCells()
        {
            Board board = new Board();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    board.Cells[i][j] = true;
                }
            }

            Assert.AreEqual(32, MaxArea.MaximalRectangle(board.Cells));
        }
Beispiel #5
0
        public void AllCells()
        {
            Board board = new Board();

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    board.Cells[i][j] = true;
                }
            }

            Assert.AreEqual(0, MaxArea.MaximalRectangle(board.Cells));
        }
Beispiel #6
0
        public void MakeAMove(out int shapeId, out string placement, Board board, IDictionary <int, Shape> shapes, IGameDrawer renderer)
        {
            placement = "";
            shapeId   = 0;
            var candidates = new List <Candidate>();

            foreach (var shape in shapes)
            {
                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        var newBoard     = new Board(board);
                        var curPlacement = "" + (char)(97 + x) + (char)(49 + y);
                        if (newBoard.TryPlace(shape.Value, curPlacement))
                        {
                            var candidate = new Candidate()
                            {
                                Placement  = curPlacement,
                                ShapeId    = shape.Key,
                                ScoreGain  = (newBoard.Score - shape.Value.Score) - board.Score,
                                CellsGain  = newBoard.CellCount() - board.CellCount(),
                                LinesScore = newBoard.LinesScore(),
                                MaxArea    = MaxArea.MaximalRectangle(newBoard.Cells),
                                FragScore  = Fragmentation.GetFragmentationScore(newBoard.Cells)
                            };
                            candidates.Add(candidate);
                        }
                    }
                }
            }

            var maxAreaList = from x in candidates orderby x.MaxArea descending, x.FragScore descending select x;
            var fragScoreList = from x in candidates orderby x.FragScore descending, x.MaxArea descending select x;

            var maxArea   = maxAreaList.First();
            var fragScore = fragScoreList.First();

            var final = fragScore.MaxArea < 0.32F ? maxArea : fragScore;

            placement = final.Placement;
            shapeId   = final.ShapeId;
        }
Beispiel #7
0
        public void SingleCornerCell()
        {
            Board board = new Board();

            board.Cells[0][0] = true;
            Assert.AreEqual(56, MaxArea.MaximalRectangle(board.Cells));
            board.Cells[0][0] = false;

            board.Cells[7][0] = true;
            Assert.AreEqual(56, MaxArea.MaximalRectangle(board.Cells));
            board.Cells[7][0] = false;

            board.Cells[0][7] = true;
            Assert.AreEqual(56, MaxArea.MaximalRectangle(board.Cells));
            board.Cells[0][7] = false;

            board.Cells[7][7] = true;
            Assert.AreEqual(56, MaxArea.MaximalRectangle(board.Cells));
            board.Cells[7][7] = false;
        }
Beispiel #8
0
        public void TestMaxHistogram()
        {
            int[] hist = new[] { 1, 1, 1, 1, 0, 1 };
            Assert.AreEqual(4, MaxArea.MaxAreaHist(hist));

            hist = new[] { 2, 2, 0, 2, 1, 0 };
            Assert.AreEqual(4, MaxArea.MaxAreaHist(hist));

            hist = new[] { 3, 3, 1, 3, 2, 1 };
            Assert.AreEqual(6, MaxArea.MaxAreaHist(hist));

            hist = new[] { 0, 4, 2, 4, 3, 2 };
            Assert.AreEqual(10, MaxArea.MaxAreaHist(hist));

            hist = new[] { 1, 5, 3, 5, 4, 0 };
            Assert.AreEqual(12, MaxArea.MaxAreaHist(hist));

            hist = new[] { 2, 6, 0, 6, 5, 1 };
            Assert.AreEqual(10, MaxArea.MaxAreaHist(hist));
        }
Beispiel #9
0
        public void QuarterOfAllCells()
        {
            Board board = new Board();

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    board.Cells[i][j] = true;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    board.Cells[i][j] = false;
                }
            }

            Assert.AreEqual(16, MaxArea.MaximalRectangle(board.Cells));
        }
Beispiel #10
0
 public override void GatherPathStats(GamePath gamePath, Board board)
 {
     gamePath.MaxArea   = (float)MaxArea.MaximalRectangle(board.Cells) / 64;
     gamePath.FragScore = Fragmentation.GetFragmentationScore(board.Cells);
 }
Beispiel #11
0
        public void EmptyMatrix()
        {
            Board board = new Board();

            Assert.AreEqual(64, MaxArea.MaximalRectangle(board.Cells));
        }