public void movePieceEvent() {
   // check for castle remove castling
   if (Math.abs((mouseX - border) / squareSize - (newMouseX - border) / squareSize) == 2
       && "A"
           .equals(
               ChessEngine.chessboard[(newMouseY - border) / squareSize][
                   (newMouseX - border) / squareSize])) {
     // (castling):
     if ((mouseX - border) / squareSize == 3) { // black
       ChessEngine.castleBlackLong = false;
       ChessEngine.castleBlackShort = false;
     } else { // white
       ChessEngine.castleWhiteLong = false;
       ChessEngine.castleWhiteShort = false;
     }
   }
   for (int i = 0; i < 8; i++) {
     System.arraycopy(ChessEngine.chessboard[i], 0, chessboard[i], 0, 8);
   }
   ChessEngine.flipBoard();
   ChessEngine.rating(1, 0);
   System.out.println(ChessEngine.sortMoves2(ChessEngine.possibleMoves()));
   if (ChessEngine.possibleMoves().length() == 0) {
     System.out.println("You win!");
     ChessEngine.flipBoard();
   } else {
     ChessEngine.makeMove(ChessEngine.printMove());
     ChessEngine.flipBoard();
     if (ChessEngine.possibleMoves().length() == 0) {
       if (ChessEngine.kingSafe()) {
         System.out.println("Stalemate");
       } else {
         System.out.println("Defeat!");
       }
     }
   }
   repaint();
 }