Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class Test {
- public static void main(String[] args) {
- Random rnd = new Random();
- int[][] board = new int[8][8];
- int [] ant = new int [10];
- int positionX = rnd.nextInt(8); //x-coordinate for the ant
- int positionY = rnd.nextInt(8); //y-coordinate for the ant
- int count = 0;
- int square = 0; //squares that have been stepped on
- boolean full = true;
- for (int i = 0; i < 10; i++) {
- positionX = rnd.nextInt(8); //x-coordinate for the ant
- positionY = rnd.nextInt(8);
- count = 0;
- square = 0;
- for (int rows = 0; rows < 8; rows++) {
- for (int columns = 0; columns < 8; columns++) {
- board[rows][columns] = 0;
- while (full) {
- int step = rnd.nextInt(4)+1;
- if (step == 1) {
- positionX++; //move right
- count++;
- }
- if (step == 2) {
- positionX--; // move left
- count++;
- }
- if (step == 3) {
- positionY++; // move up
- count++;
- }
- if (step == 4) {
- positionY--; // move down
- count++;
- }
- if (positionX < 0 || positionY < 0 || positionX > 7 || positionY > 7) {
- count++;
- step = rnd.nextInt(4)+1;
- positionX = rnd.nextInt(8); //x-coordinate for the ant
- positionY = rnd.nextInt(8);
- //System.out.println("help");
- }
- //if (board[positionX][positionX] == 64) {
- // System.out.println("bye");
- // full = true;
- //}
- //System.out.println("Y: " + positionY);
- // System.out.println("X: " + positionX);
- board[positionY][positionX] = 1;
- System.out.println(count);
- for (int j = 0; j < 8; j++) {
- for (int k = 0; k < 8 ; k++) {
- if (board[j][k] == 1){
- square++;
- //System.out.println(square);
- }
- }
- if (square == 64) {
- full = false;
- System.out.println("TEST:" + full);
- }
- else full = false;
- }
- // System.out.println(i);
- }
- }
- }
- System.out.println("Steps in simulation " + (i + 1) + " : " + count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement