Пример #1
0
        }                                                                              //冲突检测之九宫格检测(重构)

        public bool canPlaceAtSubGrid(int subX, int subY, int relX, int relY, int num) //冲突检测之九宫格检测
        {
            BoardBox subGrid  = board[subX, subY];
            int      checkNum = subGrid.getNumber(relX, relY);

            if (checkNum == 0)
            {
                bool numExists = false;
                for (int x = 0; x < 3; x += 1)
                {
                    for (int y = 0; y < 3; y += 1)
                    {
                        if ((x == relX) && (y == relY))
                        {
                            continue;
                        }
                        checkNum = subGrid.getNumber(x, y);
                        if (checkNum == num)
                        {
                            numExists = true;
                            break;
                        }
                    }
                    if (numExists)
                    {
                        break;
                    }
                }
                if (!numExists)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        public int getNumber(int x, int y)//x,y的范围均是从0到8,本方法先定位到BoardBox,再定位到具体数
        {
            int      row    = (int)Math.Floor((double)y / 3);
            int      col    = (int)Math.Floor((double)x / 3);
            BoardBox bb     = board[col, row];
            int      minorX = x - (col * 3);
            int      minorY = y - (row * 3);

            return(bb.getNumber(minorX, minorY));
        }