Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class KnightsTour1AYePeriod4 {
- private static final int row = 8;
- private static final int col = 8;
- private int count = 0;
- private int currentPosX = 1;
- private int currentPosY = 1;
- private int horizontal[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
- private int vertical[] = { -2, -1, 1, 2, 2, 1, -1, -2 };
- private int array[][];
- public KnightsTour1AYePeriod4() {
- array = new int[row][col];
- }
- public void board() {
- for (int x = 0; x < row; x++) {
- for (int y = 0; y < col; y++) {
- System.out.print(" " + array[x][y]);
- }
- System.out.println();
- }
- System.out.println();
- }
- public static int nextInt(int a, int b) {
- Random chooser = new Random();
- return chooser.nextInt(b - a + 1) + a;
- }
- public boolean onBoard(int x, int y) {
- if (x >= 1 && x < row && y >= 1 && y < row) {
- return true;
- }
- return false;
- }
- public void moves() {
- int randNum = nextInt(1, 8);
- int row2 = currentPosX;
- System.out.println("row2 = " + row2);
- System.out.println("randNum = " + randNum);
- int col2 = currentPosY;
- System.out.println("col2 = " + col2);
- int move = 0;
- for (int i = 1; i <= 64; i++) {
- if (onBoard(row2 + vertical[randNum], col2 + horizontal[randNum]) == true) {
- row2 = row2 + vertical[randNum];
- System.out.println("row2 = " + row2);
- col2 = col2 + horizontal[randNum];
- System.out.println("hello");
- System.out.println("row2 h = " + row2);
- System.out.println("col2 h= " + col2);
- // if ()
- // if (onBoard(row2,col2)) {
- array[row2][col2] = move;
- // if(onBoard (array[row2][col2])
- System.out.println(array[row2][col2]);
- } else {
- randNum = nextInt(1, 8);
- System.out.println("hello");
- }
- }
- }
- public static void main(String[] args) {
- KnightsTour1AYePeriod4 chess = new KnightsTour1AYePeriod4();
- chess.board();
- chess.moves();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement