private void get_unavailable_walls_of_cell(int[] wall, ref int cont, Cell x)
        {
            cont = 0;

            for (int i = 0; i < 4; i++)
            {
                if (x.get_wall(i) == 0 || x.get_wall(i) == 1)
                {
                    wall[cont++] = i;
                }
            }
        }
        private void cell_update(ref Cell cell)
        {
            int i = cell.x;
            int j = cell.y;

            for (int k = 0; k < 4; k++)
            {
                if (cell.get_wall(k) == 1)
                {
                    switch (k)
                    {
                    case 0:
                        if (grid[i - 1][j].visited == 1)
                        {
                            cell.block_wall(0);
                        }
                        break;

                    case 1:
                        if (grid[i + 1][j].visited == 1)
                        {
                            cell.block_wall(1);
                        }
                        break;

                    case 2:
                        if (grid[i][j - 1].visited == 1)
                        {
                            cell.block_wall(2);
                        }
                        break;

                    case 3:
                        if (grid[i][j + 1].visited == 1)
                        {
                            cell.block_wall(3);
                        }
                        break;
                    }
                }
            }
        }
Example #3
0
        public void fill_cell_depth()
        {
            Queue <Cell> que = new Queue <Cell>();

            que.Enqueue(grid[0][start_col]);

            int[] wall = new int[4];

            while (que.Count > 0)
            {
                Cell temp = que.Dequeue();

                KeyValuePair <int, int> vecin_sus = new KeyValuePair <int, int>(-1, -1);
                KeyValuePair <int, int> vecin_jos = new KeyValuePair <int, int>(-1, -1);
                KeyValuePair <int, int> vecin_st  = new KeyValuePair <int, int>(-1, -1);
                KeyValuePair <int, int> vecin_dr  = new KeyValuePair <int, int>(-1, -1);

                int dist_sus = -1;
                int dist_jos = -1;
                int dist_st  = -1;
                int dist_dr  = -1;


                for (int i = 0; i < 4; i++)
                {
                    wall[i] = temp.get_wall(i);
                }

                for (int i = 0; i < 4; i++)
                {
                    if (wall[i] != -1)
                    {
                        int dist = 0;

                        Cell aux_cell;

                        switch (i)
                        {
                        case 0:
                        {
                            aux_cell = grid[temp.x - 1][temp.y];
                            dist++;

                            Boolean ok = new Boolean();
                            ok = true;

                            while (ok)
                            {
                                //caz blocat in directia de mers
                                if (aux_cell.get_wall(0) == -1)
                                {
                                    ok = false;
                                }
                                //caz deschis in stanga
                                if (aux_cell.get_wall(2) != -1)
                                {
                                    ok = false;
                                }
                                //caz deschis in dreapta
                                if (aux_cell.get_wall(3) != -1)
                                {
                                    ok = false;
                                }

                                if (ok == true)
                                {
                                    aux_cell = grid[aux_cell.x - 1][aux_cell.y];
                                    dist++;
                                }
                            }

                            if (aux_cell.visited != 1)
                            {
                                que.Enqueue(aux_cell);
                            }

                            dist_sus  = dist;
                            vecin_sus = new KeyValuePair <int, int>(aux_cell.x, aux_cell.y);

                            break;
                        }

                        case 1:
                        {
                            aux_cell = grid[temp.x + 1][temp.y];
                            dist++;

                            Boolean ok = new Boolean();
                            ok = true;

                            while (ok)
                            {
                                //caz blocat in directia de mers
                                if (aux_cell.get_wall(1) == -1)
                                {
                                    ok = false;
                                }
                                //caz deschis in stanga
                                if (aux_cell.get_wall(2) != -1)
                                {
                                    ok = false;
                                }
                                //caz deschis in dreapta
                                if (aux_cell.get_wall(3) != -1)
                                {
                                    ok = false;
                                }

                                if (ok == true)
                                {
                                    aux_cell = grid[aux_cell.x + 1][aux_cell.y];
                                    dist++;
                                }
                            }

                            if (aux_cell.visited != 1)
                            {
                                que.Enqueue(aux_cell);
                            }

                            dist_jos  = dist;
                            vecin_jos = new KeyValuePair <int, int>(aux_cell.x, aux_cell.y);

                            break;
                        }

                        case 2:
                        {
                            aux_cell = grid[temp.x][temp.y - 1];
                            dist++;

                            Boolean ok = new Boolean();
                            ok = true;

                            while (ok)
                            {
                                //caz blocat in directia de mers
                                if (aux_cell.get_wall(2) == -1)
                                {
                                    ok = false;
                                }
                                //caz deschis in sus
                                if (aux_cell.get_wall(0) != -1)
                                {
                                    ok = false;
                                }
                                //caz deschis in jos
                                if (aux_cell.get_wall(1) != -1)
                                {
                                    ok = false;
                                }

                                if (ok == true)
                                {
                                    aux_cell = grid[aux_cell.x][aux_cell.y - 1];
                                    dist++;
                                }
                            }

                            if (aux_cell.visited != 1)
                            {
                                que.Enqueue(aux_cell);
                            }

                            dist_st  = dist;
                            vecin_st = new KeyValuePair <int, int>(aux_cell.x, aux_cell.y);

                            break;
                        }

                        case 3:
                        {
                            aux_cell = grid[temp.x][temp.y + 1];
                            dist++;

                            Boolean ok = new Boolean();
                            ok = true;

                            while (ok)
                            {
                                //caz blocat in directia de mers
                                if (aux_cell.get_wall(3) == -1)
                                {
                                    ok = false;
                                }
                                //caz deschis in sus
                                if (aux_cell.get_wall(0) != -1)
                                {
                                    ok = false;
                                }
                                //caz deschis in jos
                                if (aux_cell.get_wall(1) != -1)
                                {
                                    ok = false;
                                }

                                if (ok == true)
                                {
                                    aux_cell = grid[aux_cell.x][aux_cell.y + 1];
                                    dist++;
                                }
                            }

                            if (aux_cell.visited != 1)
                            {
                                que.Enqueue(aux_cell);
                            }

                            dist_dr  = dist;
                            vecin_dr = new KeyValuePair <int, int>(aux_cell.x, aux_cell.y);

                            break;
                        }
                        }
                    }
                }

                //mark cell as visite
                temp.visited = 1;
                //Console.Write(temp.x + " " + temp.y + "\n");
                //create it as disj cell
                cell_depth[cont_noduri] = new Cell_Depth(temp.x, temp.y);
                //set neighbours
                cell_depth[cont_noduri].set_cell_neighbour(vecin_sus, 0);
                cell_depth[cont_noduri].set_cell_neighbour(vecin_jos, 1);
                cell_depth[cont_noduri].set_cell_neighbour(vecin_st, 2);
                cell_depth[cont_noduri].set_cell_neighbour(vecin_dr, 3);
                //set distance to neighbours
                cell_depth[cont_noduri].set_dist_to_neighbour(dist_sus, 0);
                cell_depth[cont_noduri].set_dist_to_neighbour(dist_jos, 1);
                cell_depth[cont_noduri].set_dist_to_neighbour(dist_st, 2);
                cell_depth[cont_noduri].set_dist_to_neighbour(dist_dr, 3);

                cont_noduri++;

                if (temp.x == rows - 1 && temp.y == cols - 1)
                {
                    break;
                }
            }
        }