Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. public static void start(Board zz)
  2.     {
  3.         boolean canPlay = true;
  4.         Scanner s = new Scanner(System.in);
  5.         Board b = new Board();
  6.           // white even , black odd
  7.          // stores all movements
  8.    
  9.         Boolean IM;
  10.         while(canPlay)
  11.         {
  12.             if(plyTurn%2==0) {
  13.                 System.out.print("White's move: " );
  14.             }
  15.             else if(plyTurn%2!=0) {
  16.                 System.out.print("Black's move: ");
  17.             }
  18.             String input = s.nextLine();
  19.            
  20.             currentMove = input;
  21.            
  22.             /*Resign*/
  23.             if(input.equals("resign")) {
  24.                 if(plyTurn%2==0) { // white resigned
  25.                     System.out.println("Black wins");
  26.                 }
  27.                 else {
  28.                     System.out.println("White wins");
  29.                 }
  30.                 canPlay = false;
  31.                 continue;
  32.             }
  33.            
  34.             /*draw*/
  35.             else if(input.equals("draw") && input.length()==4) {
  36.                 System.out.println();
  37.                 canPlay = false;
  38.                 break;
  39.             }
  40.            
  41.            
  42.             String from = input.substring(0, 2);
  43.             String to = input.substring(3, 5);
  44.             if(from.equals("f4"))
  45.             {
  46.                 int a;
  47.                 a=0;
  48.             }
  49.             int c = (int) (from.charAt(0)) - 97; // e2 e4   //x prev
  50.             int d = 8 - Integer.parseInt(from.charAt(1) + "");//y prev
  51.             int w = (int) (to.charAt(0)) - 97; // e2 e4    // x new
  52.             int v = 8 - Integer.parseInt(to.charAt(1) + ""); // y new
  53.            
  54.             /* whites move*/
  55.             if (plyTurn%2==0) { // TODO draw
  56.            
  57.             if(zz.board[d][c]==null || zz.board[d][c].getcolor()!='w' ) { //empty spot move or not white
  58.                 System.out.println("Illegal move, try again");
  59.                 continue;
  60.             }      
  61.             if((IM=zz.move(from,to)) ||!IM ) {     
  62.                 if(IM==false) {
  63.                     System.out.print("Illegal move, try again\n");
  64.                     continue;
  65.                 }else {
  66.                     System.out.println();
  67.                 moveHistory.add(input);
  68.                 plyTurn++;
  69.                 zz.draw();     
  70.                 }
  71.             }
  72.        
  73.             if(zz.inCheckmate('b') ) { // maybe should be before above if
  74.                 System.out.println("Checkmate");
  75.                 System.out.println("White wins");
  76.                 break;
  77.             }
  78.             if(zz.check('b')) {
  79.                 System.out.println("Check");
  80.                 continue;
  81.             }              
  82.         }
  83.             else if(plyTurn%2!=0) {
  84.                 if(zz.board[d][c]==null || zz.board[d][c].getcolor()!='b' ) { //empty spot move or not white
  85.                     System.out.println("Illegal move, try again");
  86.                     continue;
  87.                 }
  88.        
  89.                 if((IM=zz.move(from,to)) ||!IM ) {     
  90.                     if(IM==false) {
  91.                         System.out.print("Illegal move, try again\n");
  92.                         continue;
  93.                     }else {
  94.                         System.out.println();
  95.                     moveHistory.add(input);
  96.                     plyTurn++;
  97.                     zz.draw();     
  98.                     }
  99.                 }
  100.            
  101.                 if(zz.inCheckmate('w') ) { // maybe should be before above if
  102.                     System.out.println("Checkmate");
  103.                     System.out.println("Black wins");
  104.                     break;
  105.                 }
  106.                 if(zz.check('w')) {
  107.                     System.out.println("Check");
  108.                     continue;
  109.                 }                            
  110.             }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement