Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Puzzle15::creatRandom15Puzzle(){
- int possibleNumbers[4][4] = {
- {0, 1, 2, 3},
- {4, 5, 6, 7},
- {8, 9, 10, 11},
- {12, 13, 14, 15}
- };
- int puzzleGenerated[4][4] = {};
- int randomNum;
- bool validNum;
- bool validPuzzle = false;
- int x = 0;
- int y = 0;
- while(y < 4){
- if(y >=4 ){
- break;
- }
- x = 0;
- while(x < 4){
- if(y > 3) {
- break;
- }
- randomNum = rand() % 16 + 0;
- validNum = true;
- for(int i=0; i < 4; i++){
- for(int j=0; j < 4; j++){
- if(puzzleGenerated[i][j] == randomNum){
- validNum = false;
- // cout << "RandomNum: " << randomNum << " puzzleGenerated: " << puzzleGenerated[i][j] << "\n";
- }
- }
- }
- if(validNum == true){
- puzzleGenerated[y][x] = randomNum;
- x++;
- cout << "X: " << x << "\n";
- }
- }
- y++;
- cout << "Y: " << y << "\n";
- if(y == 4){
- // validPuzzle = isPuzzleSolvable(puzzleGenerated);
- copyPuzzle(puzzleGenerated);
- displayPuzzle();
- break;
- // if(!validPuzzle){
- // copyPuzzle(puzzleGenerated);
- // displayPuzzle();
- // loop = false;
- // }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement