Advertisement
cupertinoCSstruggle1

Untitled

Jan 29th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. int[] horizontal = {1,2,2,1,-1,-2,-2,-1};
  2. int[] vertical = {-2,-1,1,2,2,1,-1,-2};
  3. int rowStart = 0;
  4. int colStart = 0;
  5. int counter = 0;
  6.  
  7. for(int row = 0; row < knight.length; row++) {
  8. for(int col = 0; col < knight[row].length; col++) {
  9. int num = random();
  10. rowStart += horizontal[num ];
  11. colStart += vertical[num];
  12.  
  13. if(rowStart < 0 || colStart < 0 ) {
  14. num = 0;
  15. rowStart = 0;
  16. colStart = 0;
  17. num = random();
  18. }
  19.  
  20. if(safe(rowStart, colStart) ) {
  21. knight[rowStart][colStart] = counter;
  22. counter++;
  23. }
  24. }
  25.  
  26. 0 0 0 0 0 0 0 0 0
  27. 0 0 22 5 10 0 0 18 0
  28. 0 21 0 12 17 14 7 0 0
  29. 0 0 4 9 6 0 0 0 0
  30. 0 0 0 0 13 0 0 0 0
  31. 0 0 0 0 0 0 0 0 0
  32. 0 0 0 0 0 0 0 0 0
  33. 0 0 0 0 0 0 0 0 0
  34. 0 0 0 0 0 0 0 0 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement