示例#1
0
        public int[,] Search(int startY, int startX,
                             LatticeType lattice = LatticeType.Square, SearchType search = SearchType.BFS)
        {
            switch (search) {
                case SearchType.DFS:
                    goto default;
                case SearchType.BFS:
                    board = breadthFirstSearch(startX, startY, lattice);
                    break;
                default:
                    board = depthFirstSearch(startX, startY, lattice);
                    break;
            }

            return board;
        }
示例#2
0
        int[,] breadthFirstSearch(int startY, int startX, LatticeType lattice)
        {
            this.queX.Clear();
            this.queY.Clear();
            this.initBoard();

            this.queY.Enqueue(startY);
            this.queX.Enqueue(startX);

            int[] dy, dx;

            switch (lattice) {
                case LatticeType.Square:
                    goto default;
                case LatticeType.Triangle:
                     dy = new int[]{ 0, 1, 1 };
                     dx = new int[]{ 1, 1, 0 };
                    break;
                default:
                    dy = new int[] { 0, 1 };
                    dx = new int[] { 1, 0 };
                    break;
            }

            this.board[startY, startX] = time;
            time++;

            while (this.queX.Any()) {
                int y = this.queY.Dequeue();
                int x = this.queX.Dequeue();

                for (int i = 0; i < dx.Length; i++) {
                    int nextY = y + dy[i];
                    int nextX = x + dx[i];
                    if (nextY < this.height && nextX < this.width
                        && this.board[nextY, nextX] == -1) {
                            this.queY.Enqueue(nextY);
                            this.queX.Enqueue(nextX);
                            this.board[nextY, nextX] = this.time++;
                    }
                }
            }

            return board;
        }
示例#3
0
 public void Open()
 {
     if (lt == LatticeType.Flag || lt == LatticeType.Other)
     {
         return;
     }
     if (isLei)
     {
         //GG
         Console.WriteLine("游戏结束");
         return;
     }
     if (isCanOpen)
     {
         Console.WriteLine("open");
         GameManger.instances.OpenArouond(this);
     }
     lt = LatticeType.Number;
 }
示例#4
0
        void drawLattice(double x, double y, int width, int height, int leng, LatticeType type)
        {
            if (width == 1 && height > 1) {
                this.drawLine(x, y, x, y + leng*(height-1),
                    strokeThickness: 0.5, opacity: 0.75, stroke: Brushes.Navy);
                return;
            }

            if (width > 1 && height == 1) {
                this.drawLine(x, y, x + leng*(width-1), y,
                    strokeThickness: 0.5, opacity: 0.75, stroke: Brushes.Navy);
                return;
            }

            for (int j = 0; j < height-1; j++) {
                for (int i = 0; i < width-1; i++) {
                    double sx = x + i*leng, sy = y + j*leng;
                    this.drawRect(sx, sy, width:leng, height:leng,
                        strokeThickness:0.5, opacity:0.75, stroke:Brushes.Navy);
                    if (type == LatticeType.Triangle) {
                        this.drawLine(sx, sy, sx+leng, sy+leng,
                            strokeThickness: 0.5, opacity: 0.75, stroke: Brushes.Navy);
                    }
                }
            }
        }
示例#5
0
        void dfs(int y, int x, LatticeType type)
        {
            if (this.height <= y || this.width <= x || this.board[y, x] != -1) return;

            this.board[y, x] = this.time;
            this.time++;

            switch (type) {
                case LatticeType.Square:
                    goto default;
                case LatticeType.Triangle:
                dfs(y, x + 1, type);
                dfs(y + 1, x + 1, type);
                dfs(y + 1, x, type);
                    break;
                default:
                dfs(y, x + 1, type);
                dfs(y + 1, x, type);
                    break;
            }
        }
示例#6
0
 int[,] depthFirstSearch(int startY, int startX, LatticeType lattice)
 {
     this.initBoard();
     dfs(startX, startY, lattice);
     return board;
 }