Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //hello pastebin viewers ^^ it's my own algorithm 4 creating bool map... it's useless now XD if u want to use it - just do it, but give info about author :D
- #include <iostream>
- #include <algorithm>
- #include <ctime>
- #define _ ios_base::sync_with_stdio(0);cin.tie(0);
- #define AM 50 //amount of tiles
- //#define CorUP 5 //upper border
- //#define CorDOWN 1 //lower border
- using namespace std;
- void zeruj(bool map[][AM]){
- for (int i = 0; i<AM; i++)
- for (int j = 0; j<AM; j++)
- map[i][j] = 0;
- }
- //==================================================================================================================================
- int zlicz(bool map[][AM], int pF, int pS){
- int population = 0;
- if (map[pF - 1][pS - 1] == 1) population++;
- if (map[pF - 1][pS] == 1) population++;
- if (map[pF - 1][pS + 1] == 1) population++;
- if (map[pF][pS - 1] == 1) population++;
- if (map[pF][pS + 1] == 1) population++;
- if (map[pF + 1][pS - 1] == 1) population++;
- if (map[pF + 1][pS] == 1) population++;
- if (map[pF + 1][pS + 1] == 1) population++;
- return population;
- }
- //:::::::::::::::::::::::::::::::::::
- void ruch(bool map[][AM], int step, int dir, int &pF, int &pS, int &a){
- for (int i = 0; i < step; i++){
- switch (dir){ //0 = N 1 = E 2 = S 3 = W
- case 0:
- pF--;
- break;
- case 1:
- pS++;
- break;
- case 2:
- pF++;
- break;
- case 3:
- pS--;
- break;
- }
- if (
- (pF == 0 && pS == 0) ||
- (pF == 0 && pS == AM-1) ||
- (pF == AM-1 && pS == 0 ) ||
- (pF == AM-1 && pS == AM-1)
- )a++; //sprawdza rogi mapy
- if (pF < 0 || pF > AM-1 || pS < 0 || pS > AM-1) continue;
- int chance = zlicz(map, pF, pS);
- switch (chance){
- case 0: // 1%
- if (rand() % 100 < 1) map[pF][pS] = 1;
- break;
- case 1: // 35%
- if (rand() % 100 < 35) map[pF][pS] = 1;
- break;
- case 2: // 50%
- if (rand() % 100 < 50) map[pF][pS] = 1;
- break;
- case 3: // 75%
- if (rand() % 100 < 75) map[pF][pS] = 1;
- break;
- default:// 90%
- if (rand() % 100 < 90) map[pF][pS] = 1;
- break;
- }
- }
- }
- //:::::::::::::::::::::::::::::::::::
- void zapelnij(bool map[AM][AM]){
- int rdF = rand() % AM;
- int rdS = rand() % AM;
- int a = 0; //róg mapy
- int step = 1;
- int dir = 0;
- int mov = 0;
- map[rdF][rdS] = 1;
- // int pF = rdF; //wiersz
- // int pS = rdS; //kolumna
- while (a!=4){
- ruch(map, step, dir, rdF, rdS, a);
- dir++; dir %= 4; //zmiana kierunku;
- mov++; //mówi który to był ruch
- if (mov % 2 == 0){ mov %= 2; step++; } //zwiększa krok
- }
- }
- //==================================================================================================================================
- int popraw(bool map[][AM], int CorDOWN, int CorUP){
- int count = 0;
- for (int i = 0; i < AM; i++){
- for (int j = 0; j < AM; j++){
- int tmp = zlicz(map, i, j);
- if (tmp >= CorUP){
- count++;
- map[i][j] = 1;
- }
- if (tmp <= CorDOWN){
- count++;
- map[i][j] = 0;
- }
- }
- }
- return count;
- }
- void wypisz(bool map[][AM]){
- for (int i = 0; i<AM; i++){
- for (int j = 0; j<AM; j++){
- if (map[i][j]==1) cout << "X" << " ";
- else cout << " ";
- }
- cout << "\n";
- }
- }
- //==================================================================================================================================
- int main(){
- bool map[AM][AM];
- srand(time(NULL));
- zeruj(map);
- zapelnij(map);
- wypisz(map);
- char doCorrect;
- do{
- cout << "\n======================================================================\n\n# popraw - Y / N - wyjdz \n> ";
- cin >> doCorrect;
- while (doCorrect != 'Y' && doCorrect != 'N'){
- cout << "# wpisz poprawne polecenie...\n#";
- cin >> doCorrect;
- }
- if (doCorrect == 'Y'){
- cout << "\n# podaj zakres DOWN i UP z zakresu 0-8 oraz UP>=DOWN[ rekomendowane - DONW=1 UP=5 ]\n> ";
- short int DOWN, UP;
- do{
- cin >> DOWN >> UP;
- if (DOWN < 0 || DOWN> 8 || UP < 0 || UP>8 || DOWN > UP)
- cout << "\n# podaj poprawny zakres...\n> ";
- } while (DOWN < 0 || DOWN> 8 || UP < 0 || UP>8 || DOWN > UP);
- cout << "\n======================================================================\n#" << "\n# poprawiono:\n# " << popraw(map, DOWN, UP)<< " pól\n======================================================================\n";
- wypisz(map);
- }
- } while (doCorrect != 'N');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement