public static HashMap<GamePieceName, ArrayList<BoardLocation>> getLegalMovesForPlayer(GameBoard gameboard, PlayerName player){
    HashMap<GamePieceName, ArrayList<BoardLocation>> legalMoves = new HashMap<GamePieceName, ArrayList<BoardLocation>>();
    ArrayList<BoardLocation> destinations;
    ArrayList<BoardLocation> legalDestinationsForPiece;
    GameBoard testBoard;
    for (GamePieceName pieceName : GamePieceName.values()){
      Piece piece = gameboard.getPieceByName(pieceName);
      if (piece.getOwner()!=player) continue;
      if (gameboard.getLocationOfPiece(piece)==null) continue;
      System.out.print("\n" + piece+ ": ");
      destinations = getDestinationsOfPiece(gameboard, piece, player);
      legalDestinationsForPiece = new ArrayList<BoardLocation>();
      if (destinations == null) System.err.println("this list of dests shouldn't be a nullset");
      for (BoardLocation dest:destinations){
        //GameGuiUtils.asciiOutput(gameboard);
        testBoard = gameboard.deepCopy();
        
        if (testBoard.getPieceAtLocation(dest)!=null) testBoard.clearLocation(dest);
        testBoard.movePiece(piece.getName(), dest);
        if (Testing.debug){
          System.out.println("test move: " + piece + " " + dest);
        }
        
        if (isKingInCheck(testBoard, player)==null){
          legalDestinationsForPiece.add(dest);
          System.out.print(dest+ " ");

        }
        else {
          System.err.print(dest+ " (" + isKingInCheck(testBoard, player) + ")");

        }
      }
      if (legalDestinationsForPiece.size()!=0){
        legalMoves.put(piece.getName(), legalDestinationsForPiece);
      }
    }
    return legalMoves; 
  }