Пример #1
0
    //获取合理招法
    public int NextGenerateMove(ref int[][] retval)
    {
        int        cnt       = 0;
        int        tmpcnt    = 0;
        StarsBoard mTable    = new StarsBoard();
        StarsBoard fullBoard = new StarsBoard(); //二值化完整棋盘,用于判定是否为空行

        for (int c = 0; c <= 4; c++)
        {
            fullBoard = fullBoard.Or(_starsBoard[c]);
        }
        int p;

        for (int c = 0; c <= 4; c++) //遍历颜色
        {
            mTable = new StarsBoard();
            for (int y = 0; y <= 9; y++) //遍历坐标
            {
                for (int x = 0; x <= 9; x++)
                {
                    p = (int)((x << 4) | y);
                    int[] tmpps = new int[102];
                    if (mTable.GetValue(p) == false)
                    {
                        _starsBoard[c].FillPath(mTable, fullBoard, p, ref tmpps, ref tmpcnt);
                        if (tmpcnt > 1)
                        {
                            tmpps[100]  = (int)(c);      //颜色
                            tmpps[101]  = (int)(tmpcnt); //长度
                            retval[cnt] = tmpps;         //记录结果
                            cnt++;
                        }
                    }
                }
            }
        }
        return(cnt);
    }
Пример #2
0
    //这个函数与上面的函数基本相同,但只统计连续个数不返回坐标。
    public int SumStar(StarsBoard mTable, StarsBoard FullBoard, int p)
    {
        Stack <int> mArray = new Stack <int>(); //栈——将处理点表
        int         mP     = p;                 //正在处理点
        int         mAP;                        //临时变量——可能被入栈的点
        int         cnt = System.Convert.ToInt32(0);
        int         x;
        int         i;

        mArray.Push(mP); //入栈
        do
        {
            if (mTable.GetValue(mP) == false) //若未处理过
            {
                x = mP >> 4;
                if ((this.m_Array[x] & (1 << (mP & 0xF))) != 0) //若有子
                {
                    //临近点入栈
                    if ((mP & 0xF) > 0) //上
                    {
                        mAP = (int)(mP - 1);
                        if (!mTable.GetValue(mAP))
                        {
                            mArray.Push(mAP);
                        }
                    }
                    if ((mP & 0xF) < 10) //下
                    {
                        mAP = (int)(mP + 1);
                        if (!mTable.GetValue(mAP))
                        {
                            mArray.Push(mAP);
                        }
                    }
                    if (x > 0) //左
                    {
                        mAP = (int)(mP - 0x10);
                        if (!mTable.GetValue(mAP))
                        {
                            for (i = x - 1; i >= 0; i--) //向右查找第一个非空行取坐标。
                            {
                                if (FullBoard.m_Array[i] != 0)
                                {
                                    mAP = (int)((i << 4) | (mP & 0xF));
                                    break;
                                }
                            }
                            mArray.Push(mAP);
                        }
                    }
                    if (x < 9) //右
                    {
                        mAP = (int)(mP + 0x10);
                        if (!mTable.GetValue(mAP))
                        {
                            for (i = x + 1; i <= 9; i++)
                            {
                                if (FullBoard.m_Array[i] != 0)
                                {
                                    mAP = (int)((i << 4) | (mP & 0xF));
                                    break;
                                }
                            }
                            mArray.Push(mAP);
                        }
                    }
                    cnt++;          //记录个数
                }
                mTable.SetTrue(mP); //修改为已处理
            }
            if (mArray.Count == 0)  //还有点就出栈,没有就结束
            {
                break;
            }
            else
            {
                mP = mArray.Pop();
            }
        } while (true);
        return(cnt);
    }
Пример #3
0
    //获取连通性。局面,已处理表,点坐标,连通点集,连通点集包含的点数。
    public void FillPath(StarsBoard mTable, StarsBoard FullBoard, int p, ref int[] retval, ref int retcnt)
    {
        Stack <int> mArray = new Stack <int>(); //栈——将处理点表
        int         mP     = p;                 //正在处理点
        int         mAP;                        //临时变量——可能被入栈的点
        int         cnt = System.Convert.ToInt32(0);
        int         x;
        int         i;

        mArray.Push(mP); //入栈
        do
        {
            if (mTable.GetValue(mP) == false) //若未处理过
            {
                x = mP >> 4;
                if ((this.m_Array[x] & (1 << (mP & 0xF))) != 0) //若有子
                {
                    //临近点入栈
                    if ((mP & 0xF) > 0) //上
                    {
                        mAP = (int)(mP - 1);
                        if (!mTable.GetValue(mAP))
                        {
                            mArray.Push(mAP);
                        }
                    }
                    if ((mP & 0xF) < 10) //下
                    {
                        mAP = (int)(mP + 1);
                        if (!mTable.GetValue(mAP))
                        {
                            mArray.Push(mAP);
                        }
                    }
                    if (x > 0) //左
                    {
                        mAP = (int)(mP - 0x10);
                        if (!mTable.GetValue(mAP))
                        {
                            for (i = x - 1; i >= 0; i--)
                            {
                                if (FullBoard.m_Array[i] != 0)
                                {
                                    mAP = (int)((i << 4) | (mP & 0xF)); //向左查找第一个非空行取坐标。
                                    break;
                                }
                            }
                            mArray.Push(mAP);
                        }
                    }
                    if (x < 9) //右
                    {
                        mAP = (int)(mP + 0x10);
                        if (!mTable.GetValue(mAP))
                        {
                            for (i = x + 1; i <= 9; i++) //向右查找第一个非空行取坐标。
                            {
                                if (FullBoard.m_Array[i] != 0)
                                {
                                    mAP = (int)((i << 4) | (mP & 0xF));
                                    break;
                                }
                            }
                            mArray.Push(mAP);
                        }
                    }
                    //记录本点
                    retval[cnt] = mP;
                    cnt++;
                }
                mTable.SetTrue(mP); //修改为已处理
            }
            if (mArray.Count == 0)  //还有点就出栈,没有就结束
            {
                break;
            }
            else
            {
                mP = mArray.Pop();
            }
        } while (true);
        //按Y进行排序,以便恢复局面时使用。
        Array.Sort(retval, 0, cnt, pc);
        //返回有效个数
        retcnt = cnt;
    }