Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Chess960V2.java MrG 2012.0301
- purpose: randomly find one 960 Fischer Random Chess Board refactoring version 1
- required file: chess960V2.java main class
- translator: javac chess960V2.java
- interpreter: java chess960V2
- */
- //imported classes
- import java.util.Random;
- //main class
- public class Chess960V2
- {
- public static final int BOARD_SIZE = 8;
- public static final int EVE = 0;
- public static final int ODD = 1;
- public static void main(String[] args)
- {
- String[] whitePieces = new String[BOARD_SIZE];
- setBishop(whitePieces,EVE);
- setBishop(whitePieces,ODD);
- setRandom(whitePieces,"Q");
- setRandom(whitePieces,"N");
- setRandom(whitePieces,"N");
- setFirstOpen(whitePieces,"R");
- setFirstOpen(whitePieces,"K");
- setFirstOpen(whitePieces,"R");
- System.out.println(toString(whitePieces));
- }
- public static void setFirstOpen(String[] wP, String piece)
- {
- int pos = 0;
- while(wP[pos]!=null)
- {
- pos++;
- }
- wP[pos]=piece;
- }
- public static void setRandom(String[] wP, String piece)
- {
- int pos;
- Random die = new Random();
- do
- {
- pos=die.nextInt(BOARD_SIZE);
- }
- while(wP[pos]!=null);
- wP[pos]=piece;
- }
- public static void setBishop(String[] wP, int offset)
- {
- Random die = new Random();
- wP[offset+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