1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
int randRange(int low, int high)
{
return (int)(rand() / (RAND_MAX / (double)(high - low))) + low;
}
void delArr(int arr[], int size, int pos)
{
for(int i=pos+1; i<size; i++)
swap(arr[i], arr[i-1]);
}
void printGrid_all(int grid1[N][N], int grid2[N][N], int x, int y);
void printGrid_prob(int grid[N][N], int x, int y);
void generateGrid(int grid[N][N], int lvl)
{
int ch_num[10] = {1,2,3,4,5,6,7,8,9,-1};
for(int i=0; i<N; i++)
{
for(int j=0; j<N; j++)
grid[i][j]=0;
}
cout<<"Stage1"<<endl;
int ch_num2[9];
for(int i=0; i<N; i++)
ch_num2[i]=ch_num[i];
int r=8;
for(int i=0; i<N; i++)
{
int temp = randRange(0, r);
grid[i][i]=ch_num2[temp];
delArr(ch_num2, r+1, temp);
r--;
}
cout<<"Stage2"<<endl;
printGrid_prob(grid, 0, 0);
getch();
SolveSudoku(grid);
printGrid_prob(grid, 0, 0);
getch();
int lb, given;
switch(lvl)
{
case 1://extremely easy
{
lb = 4;// this are actually 9(total in a row/coloumn) - lower bound
given = randRange(50, 60);
}
case 2://easy
{
lb = 5;
given = randRange(36, 49);
}
case 3://medium
{
lb = 5;
given = randRange(32, 35);
}
case 4://hard
{
lb = 7;
given = randRange(28, 31);
}
case 5://Evil
{
lb = 9;
given = randRange(22, 27);
}
}
cout<<"Stage3"<<endl;
int rORc = randRange(0, 1);
int ch_num3[9] = {0,1,2,3,4,5,6,7,8};
for(int i=0; i<N; i++)
ch_num3[i]=ch_num[i];
int temp;
if(rORc == 0)
{
temp = randRange(0, 8);
int r=8;
for(int i=0; i<lb; i++)
{
int temp2 = randRange(0, 8);
int temp3 = ch_num3[temp2];
grid[temp][temp3]=0;
delArr(ch_num2, r, temp2);
r--;
}
cout<<"Stage4"<<endl;
int fill_zero = 81 - given - lb;
cout<<"Fill zeros in: "<<fill_zero<<endl;
while(fill_zero != 0)
{
int tempR = randRange(0, 8);
int tempC = randRange(0, 8);
if(tempR != temp)
{
grid[tempR][tempC]=0;
fill_zero--;
}
else
continue;
}
cout<<"Stage5"<<endl;
}
else
{
temp = randRange(0, 8);
int r=8;
for(int i=0; i<lb; i++)
{
int temp2 = randRange(0, 8);
int temp3 = ch_num3[temp2];
grid[temp3][temp]=0;
delArr(ch_num2, r, temp2);
r--;
}
cout<<"Stage4"<<endl;
int fill_zero = 81 - given - lb;
cout<<"Fill zeros in: "<<fill_zero<<endl;
while(fill_zero != 0)
{
cout<<fill_zero<<endl;
int tempR = randRange(0, 8);
int tempC = randRange(0, 8);
if(tempC != temp)
{
grid[tempR][tempC]=0;
fill_zero--;
}
else
continue;
}
cout<<"Stage5"<<endl;
}
}
|