Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Chess960V4.java MrG 2012.0227
- purpose: reads 960.txt and prints 1 random board
- required files: Chess960V4.java main class
- EasyReader.java file I/O class
- translator: javac Chess960V4.java
- interpreter: java Chess960V4
- */
- //imported classes
- import java.util.Random;
- //main class
- public class Chess960V4
- {
- public static final int NUM_BOARDS = 960;
- public static final int SIZE = 8;
- public static void main(String[] args)
- {
- String[][] board = new String[SIZE][SIZE];
- Random pick = new Random();
- int choice = pick.nextInt(NUM_BOARDS-1)+1;
- String temp = "";
- EasyReader ross = new EasyReader("960.txt");
- for(int i = 0; i<choice; i++)
- {
- temp = ross.readLine();
- }
- System.out.println(temp);
- System.out.println(temp.length());
- initBoard(temp, board);
- System.out.println(toString(board));
- }
- public static void initBoard(String in, String[][] out)
- {
- for(int c = 0; c<SIZE; c++)
- {
- out[0][c]=in.substring(c+in.length()-8,c+in.length()-7).toLowerCase();
- out[1][c]="p";
- out[6][c]="P";
- out[7][c]=in.substring(c+in.length()-8,c+in.length()-7);
- }
- }
- public static String toString(String[][] out)
- {
- String temp = "";
- for(int r = 0; r<SIZE; r++)
- {
- temp += 7-r+"||";
- for(int c = 0; c<SIZE; c++)
- {
- if(out[r][c]==null)
- {
- temp += " _ ";
- }
- else
- {
- temp += " "+out[r][c]+" ";
- }
- }
- temp += "\n\n";
- }
- temp += " ========================\n";
- temp += " 0 1 2 3 4 5 6 7 ";
- return temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement