Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Chess960V1.java MrG 2013.0226
- purpose: randomly generate 1 of the 960 Fischer Random Chess Boards
- required file: Chess960V1.java main class
- translator: javac Chess960V1.java
- interpreter: java Chess960V1
- */
- import java.util.Random;
- public class Chess960V1
- {
- public static void main(String[] args)
- {
- String[] whitePieces = new String[8];
- darkBishop(whitePieces);
- lightBishop(whitePieces);
- setQueen(whitePieces);
- setKnight(whitePieces);
- setKnight(whitePieces);
- doRook(whitePieces);
- doKing(whitePieces);
- doRook(WhitePieces);
- System.out.println(toString(whitePieces));
- }
- 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[die.nextInt(4)*2+1]="B";
- }
- 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 doRook(String[] wP)
- {
- int pos=0;
- while(wP[pos]!=null)
- {
- pos++;
- }
- wP[pos]="R";
- }
- public static void doKing(String[] wP)
- {
- int pos=0;
- while(wP[pos]!=null)
- {
- pos++;
- }
- wP[pos]="K";
- }
- 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