Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Chess960V1.java MrG 2012.0227
- purpose: randomly find one 960 Fischer Random Chess Board
- required file: Chess960V1.java main class
- translator: javac Chess960V1.java
- interpreter: java Chess960V1
- */
- //imported classes
- import java.util.Random;
- //main class
- public class Chess960V1
- {
- public static void main(String[] args)
- {
- String[] whitePieces = new String[8];
- darkBishop(whitePieces);
- lightBishop(whitePieces);
- setQueen(whitePieces);
- setKnight(whitePieces);
- setKnight(whitePieces);
- doLastStep(whitePieces);
- System.out.println(toString(whitePieces));
- }
- public static void doLastStep(String[] wP)
- {
- int pos = 0;
- while(wP[pos]!=null)
- {
- pos++;
- }
- wP[pos]="R";
- while(wP[pos]!=null)
- {
- pos++;
- }
- wP[pos]="K";
- while(wP[pos]!=null)
- {
- pos++;
- }
- wP[pos]="R";
- }
- public static void setQueen(String[] wP)
- {
- int pos;
- Random die = new Random();
- do
- {
- pos=die.nextInt(8);
- }
- while(wP[pos]!=null);
- wP[pos]="Q";
- }
- public static void setKnight(String[] wP)
- {
- int pos;
- Random die = new Random();
- do
- {
- pos=die.nextInt(8);
- }
- while(wP[pos]!=null);
- wP[pos]="N";
- }
- public static void darkBishop(String[] wP)
- {
- Random die = new Random();
- wP[die.nextInt(4)*2]="B";
- }
- public static void lightBishop(String[] wP)
- {
- Random die = new Random();
- wP[1+die.nextInt(4)*2]="B";
- }
- public static String toString(String[] wP)
- {
- String temp = "";
- for(int k=0; k<wP.length; k++)
- {
- temp += wP[k];
- }
- return temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement