Advertisement
Guest User

WorkInProgress

a guest
Dec 8th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class Test {
  4. public static void main(String[] args) {
  5.  
  6. Random rnd = new Random();
  7. int[][] board = new int[8][8];
  8. int [] ant = new int [10];
  9.  
  10. int positionX = rnd.nextInt(8); //x-coordinate for the ant
  11. int positionY = rnd.nextInt(8); //y-coordinate for the ant
  12. int count = 0;
  13. int square = 0; //squares that have been stepped on
  14. boolean full = true;
  15. for (int i = 0; i < 10; i++) {
  16.  
  17. positionX = rnd.nextInt(8); //x-coordinate for the ant
  18. positionY = rnd.nextInt(8);
  19.  
  20. count = 0;
  21. square = 0;
  22.  
  23.  
  24.  
  25.  
  26. for (int rows = 0; rows < 8; rows++) {
  27. for (int columns = 0; columns < 8; columns++) {
  28. board[rows][columns] = 0;
  29.  
  30.  
  31. while (full) {
  32. int step = rnd.nextInt(4)+1;
  33. if (step == 1) {
  34. positionX++; //move right
  35. count++;
  36. }
  37.  
  38. if (step == 2) {
  39. positionX--; // move left
  40. count++;
  41. }
  42.  
  43. if (step == 3) {
  44. positionY++; // move up
  45. count++;
  46. }
  47.  
  48. if (step == 4) {
  49. positionY--; // move down
  50. count++;
  51. }
  52.  
  53. if (positionX < 0 || positionY < 0 || positionX > 7 || positionY > 7) {
  54. count++;
  55. step = rnd.nextInt(4)+1;
  56.  
  57. positionX = rnd.nextInt(8); //x-coordinate for the ant
  58. positionY = rnd.nextInt(8);
  59.  
  60. //System.out.println("help");
  61. }
  62.  
  63. //if (board[positionX][positionX] == 64) {
  64. // System.out.println("bye");
  65. // full = true;
  66. //}
  67. //System.out.println("Y: " + positionY);
  68. // System.out.println("X: " + positionX);
  69. board[positionY][positionX] = 1;
  70. System.out.println(count);
  71. for (int j = 0; j < 8; j++) {
  72. for (int k = 0; k < 8 ; k++) {
  73. if (board[j][k] == 1){
  74. square++;
  75. //System.out.println(square);
  76. }
  77. }
  78. if (square == 64) {
  79. full = false;
  80.  
  81. System.out.println("TEST:" + full);
  82. }
  83. else full = false;
  84.  
  85. }
  86. // System.out.println(i);
  87.  
  88. }
  89.  
  90.  
  91. }
  92.  
  93. }
  94. System.out.println("Steps in simulation " + (i + 1) + " : " + count);
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement