-
queens program
I have to make a program taht alows me to place 8 queens on a chest board with out having them kill on another with there repective movements.
i need to do this program by keeping trake of the movements with a multy bimentional array which i hav no idea how to do. also i have to make a program that runs through all the posible cobination of how the queen can be put on the board and some how show the qween position on an apolet.
but frist i would to know how i ould go about drawing a cheast board on and applet.
i have just started java and would really apercheat the help.
thanx
-
how do you make a multy dimentional array and compare the different part of the array to each other
-
To make a multi-dimensional array, you do as follows:
Code:
int x = 8;
int y = 8;
private int[][] ArrayName = new int [x][y];
Comparing positions in the array would probably look something like:
Code:
int firstpositionx = 3;
int firstpositiony = 4;
int secondpositionx = 5;
int secondpositiony = 2;
if ( isWithin ( firstpositionx, firstpositiony, secondpositionx, secondpositiony ) ) return true;
else return false;
You could then write a method isWithin ( int a, int b, int c, int d ) which would then take the first two integers a and b, to find a position in the array and then take integers c and d to find a second position. It would then check to see if the first position is within two spaces of the second position.
Code for a basic chess game can be found in a lot of Java books, I'm sure. Make sure you can program the actual game itself before you bother with graphics.
Hope this helps :)