Advertisement
calcpage

Chess960V4+initBoard.java

Mar 21st, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.54 KB | None | 0 0
  1. /*
  2. Chess960V4.java     MrG     2012.0227
  3. purpose:    reads 960.txt and prints 1 random board
  4. required files: Chess960V4.java             main class
  5.         EasyReader.java             file I/O class
  6. translator: javac Chess960V4.java
  7. interpreter:    java Chess960V4
  8. */
  9.  
  10. //imported classes
  11. import java.util.Random;
  12.  
  13. //main class
  14. public class Chess960V4
  15. {
  16.     public static final int NUM_BOARDS = 960;
  17.     public static final int SIZE = 8;
  18.     public static void main(String[] args)
  19.     {
  20.         String[][] board = new String[SIZE][SIZE];
  21.  
  22.         Random pick = new Random();
  23.         int choice = pick.nextInt(NUM_BOARDS-1)+1; 
  24.  
  25.         String temp = "";
  26.         EasyReader ross = new EasyReader("960.txt");       
  27.         for(int i = 0; i<choice; i++)
  28.         {
  29.             temp = ross.readLine();
  30.         }
  31.         System.out.println(temp);
  32.         System.out.println(temp.length());     
  33.         initBoard(temp, board);
  34.         System.out.println(toString(board));
  35.     }
  36.  
  37.     public static void initBoard(String in, String[][] out)
  38.     {
  39.         for(int c = 0; c<SIZE; c++)
  40.         {
  41.             out[0][c]=in.substring(c+in.length()-8,c+in.length()-7).toLowerCase();
  42.             out[1][c]="p";
  43.             out[6][c]="P";
  44.             out[7][c]=in.substring(c+in.length()-8,c+in.length()-7);
  45.         }  
  46.     }
  47.  
  48.     public static String toString(String[][] out)
  49.     {
  50.         String temp = "";
  51.         for(int r = 0; r<SIZE; r++)
  52.         {
  53.             temp += 7-r+"||";
  54.             for(int c = 0; c<SIZE; c++)
  55.             {
  56.                 if(out[r][c]==null)
  57.                 {
  58.                     temp += " _ ";
  59.                 }
  60.                 else
  61.                 {
  62.                     temp += " "+out[r][c]+" ";
  63.                 }
  64.             }
  65.             temp += "\n\n";
  66.         }      
  67.         temp += "   ========================\n";
  68.         temp += "    0  1  2  3  4  5  6  7 ";
  69.         return temp;
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement