//Chess.java MrG 2006.0228 //purpose: generate Fischer Random Boards //required files: Chess1.java // EasyWriter.java //translator phase: javac Chess.java //interpreter phase: java Chess //imported class import java.util.Random; import java.util.ArrayList; //main class public class Chess { public static void main(String[] args) { int printC = 0; ArrayList foo = new ArrayList(); initList(foo); while(printC < 960) { String[] whitePieces = new String[8]; darkBishop(whitePieces); lightBishop(whitePieces); setPiece(whitePieces, "Q"); setPiece(whitePieces, "N"); setPiece(whitePieces, "N"); lastStep(whitePieces); if(!foundB(whitePieces, foo)) { System.out.println(printC + ": \t" + toString(whitePieces)); foo.add(whitePieces); printC++; } } fileList(foo); } public static void initList(ArrayList bar) { String[] bob = {"R","N","B","Q","K","B","N","R"}; bar.add(bob); } public static boolean foundB(String[] wP, ArrayList bar) { for(int k = 0; k < bar.size(); k++) { if(sameB(bar.get(k), wP)) { return true; } } return false; } public static boolean sameB(String[] a, String[] b) { int matchC = 0; for(int k = 0; k < a.length; k++) { if(a[k].compareTo(b[k])==0) { matchC++; } } return matchC==8; } public static void fileList(ArrayList bar) { EasyWriter ross = new EasyWriter("fboards.txt"); for(int k = 0; k < bar.size(); k++) { ross.println(k + ": \t" + toString(bar.get(k))); } ross.close(); } 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 void setPiece(String[] wP, String theP) { int pos; Random die = new Random(); do { pos = die.nextInt(8); } while(wP[pos]!=null); wP[pos] = theP; } public static void lastStep(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 String toString(String[] wP) { String temp = ""; for(int k = 0; k