Esempio n. 1
0
        /// <summary>
        /// 从 blocks 里选取 block 来填充 point 这点,
        /// 遍历顺序:
        /// 从底到顶 z 逐渐变大
        /// 从后到前 y 逐渐变大
        /// 从左到右 x 逐渐变大
        /// </summary>
        /// <param name="blocks">可用积木的集合</param>
        /// <param name="point">当前要填充覆盖的点</param>
        /// <returns>是否能正确填完</returns>
        protected override bool FillBlock(Block.IBlock[] blocks, Point point)
        {
            bool bSuccess = SuccessFlag();

            if (bSuccess)
            {
                return(true);
            }

            if (blocks == null)
            {
                return(false);
            }

            point = NextEmptyPoint(point);

            for (int b = 0; b < blocks.Length; ++b)
            {
                Block.IBlock block = blocks[b];

                bool bSpecialBlock = false;
                if (this.initBlockSp != null)
                {
                    bSpecialBlock = initBlockSp.value == block.value;
                }

                //int iShapeAllCount = block.AllShapeCount();

                int iLessLayer = 1;
                if (this.bZAsc)
                {
                    iLessLayer = this.layerNum - point.z;
                }
                else
                {
                    iLessLayer = point.z + 1;
                }
                Region[] r = block.CreateRegion(iLessLayer);
                if (r != null)
                {
                    for (int t = 0; t < r.Length; ++t)
                    {
                        Point[] points = r[t] + point;

                        bool bCanFill = CanFill(points);

                        if (bCanFill && bSpecialBlock)
                        {
                            bCanFill = false;

                            foreach (var pt in points)
                            {
                                foreach (var ptSpe in initBlockSp.points)
                                {
                                    if (ptSpe.Equal(pt))
                                    {
                                        bCanFill = true;
                                        break;
                                    }
                                }
                                if (bCanFill)
                                {
                                    break;
                                }
                            }
                        }

                        if (bCanFill)
                        {
                            Fill(points, block.value);

                            bSuccess = SuccessFlag();

                            if (bSuccess)
                            {
                                timer.End();
                                ++successCount;
                                Print($"{prompt}: {successCount}th success, {timer.Spend()}");

                                if (CanContinue())
                                {
                                    timer.Start();
                                    //  erase
                                    Fill(points, 0);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            else
                            {
                                Block.IBlock[] newblocks =
                                    blocks.CreateBlocksExcludeIndex(block);

                                FillBlock(newblocks, point);

                                if (!bContinue)
                                {
                                    break;
                                }

                                //  erase
                                Fill(points, 0);
                            }
                        }
                    }
                }

                if (!bContinue)
                {
                    break;
                }
            }

            return(bSuccess);
        }
Esempio n. 2
0
        /// <summary>
        /// 从 blocks 里选取 block 来填充 point 这点,
        /// 遍历顺序:
        /// 从上到下 y 逐渐变大
        /// 从左到右 x 逐渐变大
        /// </summary>
        /// <param name="blocks">可用积木的集合</param>
        /// <param name="point">当前要填充覆盖的点</param>
        /// <returns>是否能正确填完</returns>
        protected override bool FillBlock(Block.IBlock[] blocks, Point point)
        {
            bool bSuccess = SuccessFlag();

            if (bSuccess)
            {
                return(true);
            }

            if (blocks == null)
            {
                return(false);
            }

            point = NextEmptyPoint(point);

            for (int b = 0; b < blocks.Length; ++b)
            {
                Block.IBlock block = blocks[b];
                //int iShapeCount = block.ShapeFlatCount();
                Region[] r = block.CreateRegion(1);

                if (r != null)
                {
                    for (int t = 0; t < r.Length; ++t)
                    {
                        //Point[] points = block.MoveShape(t, point);
                        Point[] points = r[t] + point;

                        if (CanFill(points))
                        {
                            Fill(points, block.value);

                            bSuccess = SuccessFlag();

                            if (bSuccess)
                            {
                                timer.End();
                                ++successCount;
                                Print($"{prompt}: {successCount}th success, {timer.Spend()}");

                                if (CanContinue())
                                {
                                    timer.Start();
                                    //  erase
                                    Fill(points, 0);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            else
                            {
                                Block.IBlock[] newblocks =
                                    blocks.CreateBlocksExcludeIndex(block);

                                FillBlock(newblocks, point);

                                if (!bContinue)
                                {
                                    break;
                                }

                                //  erase
                                Fill(points, 0);
                            }
                        }
                    }
                }

                if (!bContinue)
                {
                    break;
                }
            }

            return(bSuccess);
        }