/*
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;
import java.util.Scanner;
//main class
public class Chess960V4
{
public static final int NUM_BOARDS = 960;
public static final int SIZE = 8;
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
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));
while(true)
{
System.out.print("enter r1: ");
int r1=in.nextInt();
System.out.print("enter c1: ");
int c1=in.nextInt();
System.out.print("enter r2: ");
int r2=in.nextInt();
System.out.print("enter c2: ");
int c2=in.nextInt();
move(r1,c1,r2,c2,board);
System.out.println(toString(board));
}
}
public static void move(int r1, int c1, int r2, int c2, String [][] board)
{
board[7-r2][c2] = board[7-r1][c1];
board[7-r1][c1] = null;
}
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;
}
}