Advertisement
calcpage

APCS_CH8_Chess960R3.java

Mar 19th, 2013
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.45 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Chess960V3
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         String board="";
  8.         int choice = (int)(Math.random()*960+1);
  9.         EasyReader spock = new EasyReader("960.txt");
  10.         for(int i=0; i<choice; i++)
  11.         {
  12.             board = spock.readLine();
  13.         }
  14.         String[][] game = new String[8][8];
  15.         initBoard(board, game);
  16.         System.out.println(toString(game));
  17.         Scanner input = new Scanner(System.in);
  18.         while(true)
  19.         {
  20.             System.out.print("current row: ");
  21.             int r1 = input.nextInt();
  22.             System.out.print("current col: ");
  23.             int c1 = input.nextInt();
  24.             System.out.print("new row: ");
  25.             int r2 = input.nextInt();
  26.             System.out.print("new col: ");
  27.             int c2 = input.nextInt();
  28.             move(r1,c1,r2,c2,game);
  29.             System.out.println(toString(game));
  30.         }
  31.     }
  32.  
  33.     public static void initBoard(String board, String[][] game)
  34.     {
  35.         for(int c=0; c<8; c++)
  36.         {
  37.             game[7][c]=board.substring(c,c+1).toLowerCase();
  38.             game[6][c]="p";
  39.             game[1][c]="P";
  40.             game[0][c]=board.substring(c,c+1);
  41.         }
  42.     }
  43.  
  44.     public static String toString(String[][] game)
  45.     {
  46.         String temp="";
  47.         for(int r=7; r>=0; r--)
  48.         {
  49.             for(int c=0; c<8; c++)
  50.             {
  51.                 if(game[r][c]==null)
  52.                 {
  53.                     temp+="|_|";
  54.                 }
  55.                 else
  56.                 {
  57.                     temp+="|"+game[r][c]+"|";
  58.                 }
  59.             }
  60.             temp+="\n";
  61.         }
  62.         return temp;
  63.     }
  64.  
  65.     public static void move(int r1, int c1, int r2, int c2, String[][] game)
  66.     {
  67.         game[r2][c2] = game[r1][c1];
  68.         game[r1][c1] = null;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement