Пример #1
0
    private void GetAdjesantArea(int x, int y, int cost, ref bool[,] isIncluded, ref Vector3 positionSum, ref int numberOfCells)
    {
        Stack <CostGridCell> stack = new Stack <CostGridCell>();

        stack.Push(grid[x, y]);
        while (stack.Count > 0)
        {
            CostGridCell cell = stack.Pop();
            int          i    = cell.i;
            int          j    = cell.j;
            if (grid[i, j].cost == cost && !isIncluded[i, j] && !grid[i, j].isObstacle)
            {
                isIncluded[i, j] = true;
                positionSum     += grid[i, j].position;
                numberOfCells++;
                stack.Push(grid[i + 1, j]);
                stack.Push(grid[i - 1, j]);
                stack.Push(grid[i, j + 1]);
                stack.Push(grid[i, j - 1]);
            }
        }
    }
Пример #2
0
    private void GenerateGrid()
    {
        xlow = (int)manager.myInfo.x_low;
        zlow = (int)manager.myInfo.z_low;
        int xhigh = (int)manager.myInfo.x_high;
        int zhigh = (int)manager.myInfo.z_high;

        width  = xhigh - xlow;
        height = zhigh - zlow;

        grid = new CostGridCell[width, height];

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                int tmp_x       = manager.myInfo.get_i_index(xlow + j);
                int tmp_z       = manager.myInfo.get_j_index(zlow + i);
                int canTraverse = (int)manager.myInfo.traversability[tmp_x, tmp_z];
                grid[j, i] = new CostGridCell(new Vector3(j + xlow + 0.5f, 0f, i + zlow + 0.5f), canTraverse == 1, j, i, enemies.Length);
            }
        }
    }