Advertisement
calcpage

Chess960V4+toString.java

Mar 20th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.15 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.         //initBoard(temp,board);
  32.         System.out.println(toString(board));
  33.     }
  34.  
  35.     public static String toString(String[][] out)
  36.     {
  37.         String temp = "";
  38.         for(int r = 0; r<SIZE; r++)
  39.         {
  40.             temp += 7-r+"||";
  41.             for(int c = 0; c<SIZE; c++)
  42.             {
  43.                 if(out[r][c]==null)
  44.                 {
  45.                     temp += " _ ";
  46.                 }
  47.             }
  48.             temp += "\n\n";
  49.         }      
  50.         temp += "   ========================\n";
  51.         temp += "    0  1  2  3  4  5  6  7 ";
  52.         return temp;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement