Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Chess960V3
- {
- public static void main(String[] args)
- {
- String board="";
- int choice = (int)(Math.random()*960+1);
- EasyReader spock = new EasyReader("960.txt");
- for(int i=0; i<choice; i++)
- {
- board = spock.readLine();
- }
- String[][] game = new String[8][8];
- initBoard(board, game);
- System.out.println(toString(game));
- Scanner input = new Scanner(System.in);
- while(true)
- {
- System.out.print("current row: ");
- int r1 = input.nextInt();
- System.out.print("current col: ");
- int c1 = input.nextInt();
- System.out.print("new row: ");
- int r2 = input.nextInt();
- System.out.print("new col: ");
- int c2 = input.nextInt();
- move(r1,c1,r2,c2,game);
- System.out.println(toString(game));
- }
- }
- public static void initBoard(String board, String[][] game)
- {
- for(int c=0; c<8; c++)
- {
- game[7][c]=board.substring(c,c+1).toLowerCase();
- game[6][c]="p";
- game[1][c]="P";
- game[0][c]=board.substring(c,c+1);
- }
- }
- public static String toString(String[][] game)
- {
- String temp="";
- for(int r=7; r>=0; r--)
- {
- for(int c=0; c<8; c++)
- {
- if(game[r][c]==null)
- {
- temp+="|_|";
- }
- else
- {
- temp+="|"+game[r][c]+"|";
- }
- }
- temp+="\n";
- }
- return temp;
- }
- public static void move(int r1, int c1, int r2, int c2, String[][] game)
- {
- game[r2][c2] = game[r1][c1];
- game[r1][c1] = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement