//make sure the piece is owned by the player
if (piece.getColor()==player.getSide()) {
//get all movements that are allowed for the selected piece
ArrayList<ArrayList<Integer>> legalMoves = possiblePieceMoves(piece, false);
//array coordinates for new destination
Index newLoc = getBoard().notationToIndex(destSq);
//find out if destination location is included in the legal moves list
ArrayList<Integer> x = legalMoves.get(0); //list of row numbers
ArrayList<Integer> y = legalMoves.get(1); //list of column numbers
ListIterator<Integer> xList = x.listIterator(); //row iterator
ListIterator<Integer> yList = y.listIterator(); //column iterator
int xL, yL;
while (xList.hasNext() && yList.hasNext()) { //while lists have coordinates
//listiterator next() method doesn't work inside if statement -> assign to variables
xL = xList.next();
yL = yList.next();
if (newLoc.getX()==xL && newLoc.getY()==yL) { //legal move
getBoard().removePiece(newLoc.getX(), newLoc.getY()); //remove captured piece from the board
piece.setRow(newLoc.getX()); //change piece row
piece.setCol(newLoc.getY()); //change piece column
// board.updateGameState(); //populate the board with new location of pieces.
//place source and destination square to history of moves
if (player.getSide()==0) { //if white
getHistoryOfMoves().addWhiteMove(srcSq, destSq); //add white piece move to history
} else if (player.getSide()==1) { //if black