Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.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.         while(canPlay)
  10.         {
  11.             if(plyTurn%2==0) {
  12.                 System.out.print("White's move: " );
  13.             }
  14.             else if(plyTurn%2!=0) {
  15.                 System.out.print("Black's move: ");
  16.             }
  17.             String input = s.nextLine();
  18.             System.out.println();
  19.             currentMove = input;
  20.            
  21.             /*Resign*/
  22.             if(input.equals("resign")) {
  23.                 if(plyTurn%2==0) { // white resigned
  24.                     System.out.println("Black wins");
  25.                 }
  26.                 else {
  27.                     System.out.println("White wins");
  28.                 }
  29.                 canPlay = false;
  30.                 break;
  31.             }
  32.            
  33.             /*draw*/
  34.             else if(input.equals("draw") && input.length()==4) {
  35.                 canPlay = false;
  36.                 break;
  37.             }
  38.            
  39.            
  40.             String from = input.substring(0, 2);
  41.             String to = input.substring(3, 5);
  42.             if(from.equals("f4"))
  43.             {
  44.                 int a;
  45.                 a=0;
  46.             }
  47.             int c = (int) (from.charAt(0)) - 97; // e2 e4   //x prev
  48.             int d = 8 - Integer.parseInt(from.charAt(1) + "");//y prev
  49.             int w = (int) (to.charAt(0)) - 97; // e2 e4    // x new
  50.             int v = 8 - Integer.parseInt(to.charAt(1) + ""); // y new
  51.            
  52.             /* whites move*/
  53.             if (plyTurn%2==0) { // TODO draw
  54.            
  55.             if(zz.board[d][c]==null || zz.board[d][c].getcolor()!='w' ) { //empty spot move or not white
  56.                 System.out.println("Illegal move, try again");
  57.                 continue;
  58.             }      
  59.             if(zz.move(from,to) ) {        
  60.                 moveHistory.add(input);
  61.                 plyTurn++;
  62.                 zz.draw();                           
  63.             }
  64.        
  65.             if(zz.inCheckmate('b') ) { // maybe should be before above if
  66.                 System.out.println("Checkmate");
  67.                 //Systen.out.println("Black wins");
  68.                 break;
  69.             }
  70.             if(zz.check('b')) {
  71.                 System.out.println("check");
  72.                 continue;
  73.             }          
  74.             if(input.length()==11 && zz.move(from,to)) { //TODO special cases  remeber enpassant
  75.                
  76.                 plyTurn++;
  77.                 zz.draw();
  78.                 moveHistory.add(input);
  79.                 //Systen.out.println("****&&&&&&");
  80.                 continue;
  81.                
  82.             }
  83. //          System.out.println("****&&&&&&" +  zz.move(from,to));
  84.              
  85.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement