Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] horizontal = {1,2,2,1,-1,-2,-2,-1};
- int[] vertical = {-2,-1,1,2,2,1,-1,-2};
- int rowStart = 0;
- int colStart = 0;
- int counter = 0;
- for(int row = 0; row < knight.length; row++) {
- for(int col = 0; col < knight[row].length; col++) {
- int num = random();
- rowStart += horizontal[num ];
- colStart += vertical[num];
- if(rowStart < 0 || colStart < 0 ) {
- num = 0;
- rowStart = 0;
- colStart = 0;
- num = random();
- }
- if(safe(rowStart, colStart) ) {
- knight[rowStart][colStart] = counter;
- counter++;
- }
- }
- 0 0 0 0 0 0 0 0 0
- 0 0 22 5 10 0 0 18 0
- 0 21 0 12 17 14 7 0 0
- 0 0 4 9 6 0 0 0 0
- 0 0 0 0 13 0 0 0 0
- 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement