void ObstacleGenerator::GenEasy(Obstacle *result) {
    int n = Random(4);
    int i, j;
    Obstacle *o = result; // shorthand
    switch (n) {
        case 0:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the row of the bonus
            FillRow(result, i + (Random(2) ? 1 : -1)); // horizontal bar next to i
            break;
        case 1:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the column of the bonus
            FillCol(result, i + (Random(2) ? 1 : -1)); // vertical bar next to i
            break;
        case 2:
            FillRow(result, 0);
            FillRow(result, OBS_GRID_SIZE - 1);
            FillCol(result, 0);
            FillCol(result, OBS_GRID_SIZE - 1);
            break;
        default:
            i = Random(0, OBS_GRID_SIZE - 2); // i is the row of the bonus
            j = Random(0, OBS_GRID_SIZE - 2); // i is the row of the bonus
            o->grid[i][j] = o->grid[i+1][j] = o->grid[i][j+1] = o->grid[i+1][j+1] = true;
            break;
    }
}
void ObstacleGenerator::GenHard(Obstacle *result) {
    int n = Random(4);
    int i;
    int j;
    switch (n) {
        case 0:
            i = Random(0, OBS_GRID_SIZE - 3);
            FillRow(result, i);
            FillRow(result, i + 1);
            FillRow(result, i + 2);
            FillRow(result, i + 3);
            result->grid[Random(0, OBS_GRID_SIZE)][Random(0, OBS_GRID_SIZE)] = false;
            break;
        case 1:
            i = Random(0, OBS_GRID_SIZE - 3);
            FillCol(result, i);
            FillCol(result, i + 1);
            FillCol(result, i + 2);
            FillCol(result, i + 3);
            result->grid[Random(0, OBS_GRID_SIZE)][Random(0, OBS_GRID_SIZE)] = false;
            break;
        case 2:
            i = Random(0, OBS_GRID_SIZE);
            for (j = 0; j < OBS_GRID_SIZE; j++) {
                if (i != j) {
                    FillCol(result, i);
                }
            }
            result->grid[Random(0, OBS_GRID_SIZE)][Random(0, OBS_GRID_SIZE)] = false;
            break;
        default:
            i = Random(0, OBS_GRID_SIZE);
            for (j = 0; j < OBS_GRID_SIZE; j++) {
                if (i != j) {
                    FillRow(result, i);
                }
            }
            result->grid[Random(0, OBS_GRID_SIZE)][Random(0, OBS_GRID_SIZE)] = false;
            break;
    }
}
void ObstacleGenerator::GenMedium(Obstacle *result) {
    int n = Random(3);
    int i;
    switch (n) {
        case 0:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the row of the bonus
            FillRow(result, i + 1);
            FillRow(result, i - 1);
            break;
        case 1:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the column of the bonus
            FillCol(result, i - 1);
            FillCol(result, i + 1);
            break;
        default:
            i = Random(1, OBS_GRID_SIZE - 1); // i is the column of the bonus
            FillRow(result, i);
            FillCol(result, i);
            break;

    }
}
Exemple #4
0
std::vector<std::vector<int>>& SetColAndRowTo0IfElemIs0(std::vector<std::vector<int>>& x)
{
	size_t N = x.size();
	if (N == 0) {
		return x;
	}
	size_t M = x[0].size();
	if (M == 0) {
		return x;
	}
	bool firstRowHas0 = RowHas0(x, 0);
	bool firstColHas0 = ColHas0(x, 0);

	for (size_t i = 1; i < N; i++) {
		bool r0 = x[i][0] == 0;
		for (size_t j = 1; j < M; j++) {
			bool c0 = x[0][j] == 0;
			if (x[i][j] == 0) {
				if (!r0) {
					r0 = true;
					FillRow(x, i, 0, j - 1);
				}
				if (!c0) {
					c0 = true;
					FillCol(x, j, 0, i - 1);
				}
			}
			else if (r0 || c0) {
				x[i][j] = 0;
			}
		}
	}
	if (firstRowHas0)
		FillRow(x, 0, 0, M - 1);
	if (firstColHas0)
		FillCol(x, 0, 0, N - 1);
	return x;
}