Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 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.                 break;
  32.             }
  33.            
  34.             /*draw*/
  35.             else if(input.equals("draw") && input.length()==4) {
  36.                 canPlay = false;
  37.                 break;
  38.             }
  39.            
  40.            
  41.             String from = input.substring(0, 2);
  42.             String to = input.substring(3, 5);
  43.             if(from.equals("f4"))
  44.             {
  45.                 int a;
  46.                 a=0;
  47.             }
  48.             int c = (int) (from.charAt(0)) - 97; // e2 e4   //x prev
  49.             int d = 8 - Integer.parseInt(from.charAt(1) + "");//y prev
  50.             int w = (int) (to.charAt(0)) - 97; // e2 e4    // x new
  51.             int v = 8 - Integer.parseInt(to.charAt(1) + ""); // y new
  52.            
  53.             /* whites move*/
  54.             if (plyTurn%2==0) { // TODO draw
  55.            
  56.             if(zz.board[d][c]==null || zz.board[d][c].getcolor()!='w' ) { //empty spot move or not white
  57.                 System.out.println("Illegal move, try again");
  58.                 continue;
  59.             }      
  60.             if((IM=zz.move(from,to)) ||!IM ) {     
  61.                 if(IM==false) {
  62.                     System.out.print("Illegal move, try again\n");
  63.                     continue;
  64.                 }else {
  65.                     System.out.println();
  66.                 moveHistory.add(input);
  67.                 plyTurn++;
  68.                 zz.draw();     
  69.                 }
  70.             }
  71.        
  72.             if(zz.inCheckmate('b') ) { // maybe should be before above if
  73.                 System.out.println("Checkmate");
  74.                 //Systen.out.println("Black wins");
  75.                 break;
  76.             }
  77.             if(zz.check('b')) {
  78.                 System.out.println("check");
  79.                 continue;
  80.             }          
  81.             if(input.length()==11 && zz.move(from,to)) { //TODO special cases  remeber enpassant
  82.                
  83.                 plyTurn++;
  84.                 zz.draw();
  85.                 moveHistory.add(input);
  86.                 //Systen.out.println("****&&&&&&");
  87.                 continue;
  88.                
  89.             }
  90.              
  91.         }
  92.             else if(plyTurn%2!=0) {
  93.                 if(zz.board[d][c]==null || zz.board[d][c].getcolor()!='b' ) { //empty spot move or not white
  94.                     System.out.println("Illegal move, try again");
  95.                     continue;
  96.                 }
  97.        
  98.                 if((IM=zz.move(from,to)) ||!IM ) {     
  99.                     if(IM==false) {
  100.                         System.out.print("Illegal move, try again\n");
  101.                         continue;
  102.                     }else {
  103.                         System.out.println();
  104.                     moveHistory.add(input);
  105.                     plyTurn++;
  106.                     zz.draw();     
  107.                     }
  108.                 }
  109.            
  110.                 if(zz.inCheckmate('w') ) { // maybe should be before above if
  111.                     System.out.println("Checkmate");
  112.                     System.out.println("White wins");
  113.                     break;
  114.                 }
  115.                 if(zz.check('w')) {
  116.                     System.out.println("check");
  117.                     continue;
  118.                 }          
  119.                 if(input.length()==11 && zz.move(from,to)) { //TODO special cases  remeber enpassant
  120.                    
  121.                     plyTurn++;
  122.                     zz.draw();
  123.                     moveHistory.add(input);
  124. //         
  125.                     continue;
  126.                    
  127.                 }
  128.                  
  129.             }
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement